php and mysql date time difference -
i did in php store lastlogin in mysql datetime column
date('y-m-d h:i:s') //which gave > '2014-01-04 08:00:56'
and saved it
when need calculate users have been online more 20 minutes, did in mysql
select * `elc_users` timestampdiff( minute , lastlogin, now( ) ) <20
it didn't work, when traced in mysql, now()
gave > 2014-01-04 20:00:56
now wont let me 20 minutes logged in users.
how can fix this?
edit
i inserted record manually in phpmyadmin, sure whthear timezone issue in timestamp
column default value current_timestamp
, gave 2014-01-05 06:48:21
. ran query in phpmyadmin
select created, now( ) `elc_users`
this gave 2014-01-05 18:53:53
now exec code below check global , session timezone, , got phpmyadmin
mysql> select @@global.time_zone, @@session.time_zone;
which gave system | system
like filip said it's timezone issue; can change timezone of script whatever timezone mysql set this:
date_default_timezone_set('america/los_angeles');
Comments
Post a Comment