Ano-Tech Computers
Enter keyword:

MySQL: datetime column uses correct timezone, NOW() does not
Problem:
When inserting data into a table that contains a 'datetime' type column, the timestamp is stored in the same timezone as the MySQL server is configured with. Unfortunately, when trying to query the same table using timestamps based on the NOW() function, I get the incorrect data because NOW() always seems to return the present time in UTC. How can I fix this?
 
Solution:
Use the following MySQL-specific command:
SET SESSION time_zone = '+1:00'

+1:00 corresponds to CET, replace with your own timezone.

You may have to adjust for Daylight Saving Time, I really don't know...

 
Discuss this solution
Did this article solve your problem? Yes No Did not apply

We welcome anyone who is willing to contribute to this public knowledge base, contact siteadmin@atc.no if you have information you would like to share. The idea is not to replace the commercial support sites, but to publish those hard-to-find solutions you've found yourself looking for over and over again.

Show all articles