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\'
and th
I don't think that this would be a timezone issue because PHP and MySQL both are running on same machine so both would be getting same time on calling current datetime. May be you can try this because I tried this on my machine as you said.
SELECT * FROM `elc_users` WHERE lastlogin < date_add(NOW(), INTERVAL -20 MINUTE)
Like Filip said it's probably a timezone issue; you can change the timezone of your script to whatever timezone your MySQL is set to like this:
date_default_timezone_set('America/Los_Angeles');
In order to avoid such problems, check the following things.
system time
and system timezone
of both the DB Server and the Application Server are same. dateTime
field in them. Personally, I suggest that you write a common function somewhere in your code, and whenever you need to get the current time, use that function, instead of using the MySQL's NOW()
I solved the problem by deleting the date column and created it again. this now recorded the time in the correct format
timestamp
gave 2014-01-04 20:58:56
, and NOW()
gave 2014-01-04 20:58:56
thanks for all who contributed, this wasn't a timezone issue as @AbdulJabbarWebBestow mentioned
Thanks again