views:

189

answers:

1

Either I'm being stupid or something's wrong here.

I have two SQL Servers, the one is on my local machine (local time +2 GMT) and the other is somewhere else (NOW() seems to return +8 GMT)and I access it through phpMyAdmin. I have a table that has a DATETIME column. I'm -trying- to store the current GMT/UTC time and then display it again, still as GMT/UTC time.

Originally I stored DATE_SUB(NOW(), INTERVAL 8 HOUR) which worked just fine. However, then I read about UTC_TIMESTAMP() and liked it more, as it was shorter. And the MySQL manual even said, "The current time zone setting does not affect values displayed by functions such as UTC_TIMESTAMP() or values in DATE, TIME, or DATETIME columns."

So perfect right? Except no.

Let's assume GMT is currently 2010-02-18 17:18:17 (I even double checked it with someone in Britain).

On my local (+2) server, I get the following results for the following queries: SELECT NOW(); 2010-02-18 19:18:17

SELECT UTC_TIMESTAMP(); 2010-02-18 17:18:17

On my online server I get: SELECT NOW(); 2010-02-19 01:18:17

SELECT UTC_TIMESTAMP(); 2010-02-19 07:18:17 (WHY?!)

Am I missing something?!

+1  A: 

Probably because the clock are wrong on the online server?

Try running this:

SELECT  @@system_time_zone, NOW(), UTC_TIMESTAMP()

and see which zone does it return and does it match the difference.

Quassnoi
@@system_time_zone NOW() UTC_TIMESTAMP()CST 2010-02-19 01:35:30 2010-02-19 07:35:30So, if I'm understanding this right, the server says it's CST (-6) and it's set to 1:35am, so SQL's saying well then add 6 to get to UTC...BAH! How frustrating.Thanks for clearing it up, I thought I was doing something wrong it's been driving me insane.
Alex