PHP / MySQL日期/时间差 [英] PHP/MySQL date/time difference

查看:180
本文介绍了PHP / MySQL日期/时间差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用PHP时遇到了一些麻烦: $ 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屋!

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