将php datetime存储在mysql数据库中 [英] Store php datetime in mysql database
问题描述
我不敢相信我无法做到这一点,但我希望能够将当前日期和时间从php存储到mysql表中.
I can't believe I can't do this, but I want to be able to store the current date and time from php in to a mysql table.
表中的列为datetime类型. 我已经尝试过了
The column in the table is type datetime. I've tried this
$current_date = date("Y-m-d");
$my_date = strtotime($current_date);
INSERT INTO my_table (date_time) VALUES ('$my_date')
但是我的时间戳记为0000-00-00 00:00:00
but my timestamp comes up as 0000-00-00 00:00:00
这必须很容易做到,但我无法使其正常工作! 我想使用来自php的时间戳,而不是使用mysql now()函数
This must be so easy to do but I just can't get it working! I want to use the timestamp from php rather than using the mysql now() function
推荐答案
不要将其另存为Unix Timestamp(由strtotime()
输出),而是另存为"2012-12-02 13:00"到DATETIME列中
Don't save it as the Unix Timestamp (which strtotime()
outputs), but as "2012-12-02 13:00" into the DATETIME column.
这篇关于将php datetime存储在mysql数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!