开发者

How can SELECT UTC_TIMESTAMP() return -10:00 UTC?

开发者 https://www.devze.com 2022-12-20 19:10 出处:网络
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 acc

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 DAT开发者_JAVA技巧ETIME 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 Current GMT is 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?!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消