以日期时间格式插入当前日期 mySQL [英] Insert current date in datetime format mySQL

查看:40
本文介绍了以日期时间格式插入当前日期 mySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将日期正确插入我的数据库时遇到问题.

I'm having problems getting the date inserted properly into my database.

$date = date('m/d/Y h:i:s', time());

我使用这种格式,并且它正确地回显出来,但是,当我插入时

I use this format, and, it echoes out correctly, however, when, I insert

mysql_query("INSERT INTO table 
(dateposted) 
VALUES ('$date')");

它似乎没有成功运行,并且,时间仍然是 00:00:00如果你能找到很好的解决方案,谢谢.

it doesn't appear to work successfully, and, the time remains 00:00:00 If you could find the solution that would be great, thanks.

推荐答案

如果您想存储当前时间,请使用 MYSQL 的函数.

If you're looking to store the current time just use MYSQL's functions.

mysql_query("INSERT INTO `table` (`dateposted`) VALUES (now())");

如果你需要用PHP来做,格式Y-m-d H:i:s所以试试

If you need to use PHP to do it, the format it Y-m-d H:i:s so try

$date = date('Y-m-d H:i:s');
mysql_query("INSERT INTO `table` (`dateposted`) VALUES ('$date')");

这篇关于以日期时间格式插入当前日期 mySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆