Different times in mysql and the server! How can they be equal?

May 2, 2014 3.9k views
I'm running nginx php and mysql in the same droplet but php and mysql gives different times. Mysql is approximately 8 hours before the php time. Actually, I need only to have the UTC times both in php and mysql. What should I do?
2 Answers
What OS are you using? You can check the system timezone on Ubuntu or Debian with:

cat /etc/timezone

and you can set it to something else using:

sudo dpkg-reconfigure tzdata

You can check the mysql timezone with:

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

You can check the php timezone with:

$tz = date_default_timezone_get();
echo $tz;

Both php and mysql should have defaulted to system time, but if they aren't respecting that for some reason you can change them.

In mysql:

SET GLOBAL time_zone = timezone;

In php:


See also:

Thanks Andrew!
It was helpful information.
Thanks again.
Have another answer? Share your knowledge.