php和mysql日期时差 [英] php and mysql date time difference

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

问题描述

我在php中这样做是将lastlogin存储在mysql datetime列中

I did this in php to store the lastlogin in a mysql datetime column

date('Y-m-d h:i:s') //which then gave > '2014-01-04 08:00:56'

然后保存

当我需要计算超过20分钟在线的用户时,我在mysql中这样做了。

When I need to calculate users who have been online more than 20 minutes, I did this in mysql

SELECT * FROM `elc_users`  WHERE TIMESTAMPDIFF( MINUTE , lastlogin, NOW( ) ) <20

它不起作用,当我在mysql中跟踪时, Now()给了这个> 2014-01-04 20:00:56

it didn't work, when I traced in mysql, Now() gave this > 2014-01-04 20:00:56

现在这不会让我得到我20分钟的用户登录。

Now this wont let me get my 20 minutes logged in users.

我如何解决这个问题?

编辑

phpMyAdmin,要确保其时区问题在时间戳列中,默认值 current_timestamp ,则它给出了$ code> 2014-01-05 06:48:21 。我在phpMyAdmin中运行这个查询

I inserted a record manually in phpMyAdmin, to be sure whthear its timezone issue in a timestamp column with default value current_timestamp, it gave 2014-01-05 06:48:21. I the ran this query in phpMyAdmin

SELECT created, NOW( )  `elc_users`

这给了 2014-01-05 18:53:53

现在我还执行下面的代码来检查全局和会话时区,我有phpMyAdmin

Now i also exec the code below to check the global and session timezone, and i got phpMyAdmin

mysql> SELECT @@global.time_zone, @@session.time_zone;

然后给出 SYSTEM |系统

推荐答案

我通过删除日期列并重新创建了解决方案。
现在以正确的格式记录时间

I solved the problem by deleting the date column and created it again. this now recorded the time in the correct format

timestamp 2014 -01-04 20:58:56 NOW() 2014-01-04 20:58: 56

感谢所有贡献者,这不是@AbdulJabbarWebBestow提到的时区问题

thanks for all who contributed, this wasn't a timezone issue as @AbdulJabbarWebBestow mentioned

再次感谢

这篇关于php和mysql日期时差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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