PHP / MySQL日期/时间差 [英] PHP/MySQL date/time difference
问题描述
$ now = date('Ymd H:i:s',time());
和MySQL:
更新用户SET user_lastactivity = NOW()
问题是,在我的数据在数据库中,当我比较两者时,有25秒的差异?为什么会发生这种情况,当他们都用于同一时间(现在),我如何可以解决这个。谢谢你们!
现在
会给你这个函数执行的时间。
在您的情况下,您正在执行的时间不同。
如果要同时使用这两个语句,您可以分配 $ now = NOW();
并在两个地方使用这个$。在查询和比较。
更新用户SET user_lastactivity = $ now
;
I've faced a little trouble while i'm working with PHP:$now = date('Y-m-d H:i:s', time());
and MySQL: UPDATE users SET user_lastactivity=NOW()
The problem is, that after i have my data in DB, and when i compare both of them, there is 25 sec difference ... why this happens, when both of them are used for same time (now) and how i can fix this.Thank you guys!
now
will give you the time when this function is being executed.
And in you case the are being executed at different time.
If you want to use same time for both statement you can assign $now = NOW();
And use this $now in both places. In query as well as for comparison.
UPDATE users SET user_lastactivity = $now
;
这篇关于PHP / MySQL日期/时间差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!