[英]Working with strtotime and MySQL
This works... 这有效...
mysqli_query
($con, "
INSERT INTO myDB (id, name, mydate)
VALUES ('$id', '$name', now())
")
This doesn't work.... 这行不通...
mysqli_query
($con, "
INSERT INTO myDB (id, name, mydate)
VALUES ('$id', '$name', date('Y-m-d H:i:s', strtotime('+5 hour')))
")
The mydate
column in MySQL is of datetime
format. MySQL中的
mydate
datetime
格式。
Any ideas why it's not working? 任何想法为什么它不起作用? I'm currently using
now()
, but I want it to show the time in my timezone, not the server's timezone. 我当前正在使用
now()
,但是我希望它显示我的时区中的时间,而不是服务器的时区。
I'd suggest storing the date in a variable first. 我建议先将日期存储在变量中。
$date = date('Y-m-d H:i:s', strtotime('+5 hour'));
If both your MySQL and PHP servers are operating on the same time-zone and have their clocks properly synchronized, you wont have an issue. 如果您的MySQL和PHP服务器都在同一时区运行,并且它们的时钟正确同步,那么您就不会有问题。
and then execute the query like so: 然后像这样执行查询:
mysqli_query($con, "
INSERT INTO myDB (id, name, mydate)
VALUES ('$id', '$name', '$date')
")
I hope this helps! 我希望这有帮助!
strtotime() is not MySQL function, its PHP function, you need to write it for being executes... strtotime()不是MySQL函数,它不是PHP函数,您需要编写它以便执行...
"INSERT INTO myDB (id, name, mydate)
VALUES ('$id', '$name', '".date('Y-m-d H:i:s', strtotime('+5 hour'))."'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.