以日期时间格式mySQL插入当前日期 [英] Insert current date in datetime format mySQL
本文介绍了以日期时间格式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屋!
查看全文