MySQL timezone, NOW() command problems

raydarken

New Member
Messages
2
Reaction score
0
Points
0
Hello, I am trying to use the mysql command NOW() in order to retrieve the latest records from the last 10 minutes in my database. The problem I am having is that the NOW() function returns a timezone that is different than the one being reported as being used on the server, making the function useless for me unless I convert my timestamps from UTC to some other timezone. Can anyone please help me understand why the timezones on this MySQL server seem so strange? Thank you in advance.

I am on the cossacks server.

Using the sql command "show variables like "%time_zone%";" returns:
system_time_zone CST
time_zone SYSTEM

At
2010-02-09 07:00:00 GMT: (2010-02-09 01:00:00 CST):

The NOW() time reads:
2010-02-10 03:00:00 (+8 Hours! A different day! unknown timezone, should be CST?)

The UTC_TIMESTAMP() time reads:
2010-02-10 09:00:00 (+14 Hours! A different day! UTC should be 07:00:00)
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Note that the value returned by NOW() is 6 hours behind UTC_TIMESTAMP(), so those at least are consistent. Try PHP's time functions; on Lotus, they report a timezone of EST and the correct time for that timezone. MySQL is 14 hours, 16 seconds fast relative to the PHP functions. I'm not certain what's going on with the MySQL server.

To have NOW work with UTC rather than the server timezone, you can set the timezone on a per-connection basis:
Code:
SET time_zone = '+0:00';

Read over § 9.7 of the MySQL manual, "MySQL Server Time Zone Support", for more information.
 
Last edited:
Top