MySQL query for current GMT time
Just use UTC (doesnt get affected with daylight savings time)
SELECT UTC_TIMESTAMP();
Old Content for reference:
this should work, but with
SELECT CONVERT_TZ(NOW(),'PST','GMT');
i got also NULL as result. funny enough the example in the mysql docu also returns null
SELECT CONVERT_TZ('2004-01-01 12:00:00','GMT','MET');
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_convert-tzseems you found a bug in mysql. (thanks to +Stephen Pritchard)
you could try:
SET @OLD_TIME_ZONE=@@TIME_ZONE;SET TIME_ZONE='+00:00';SELECT NOW();SET TIME_ZONE=@OLD_TIME_ZONE;
ok is not exactly what you wanted (its 4 queries, but only one select :-)
NO BUG in CONVERT_TZ()
To use CONVERT_TZ() you need to install the time-zone tables otherwise MySql returns NULL.
From the CLI run the following as root
# mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql
SEE http://dev.mysql.com/doc/refman/5.5/en/time-zone-support.html
Thanks
http://www.ArcanaVision.com (SJP 2011-08-18)
Note:GMT might have DSTUTC does not have DST
SELECT UTC_TIMESTAMP();
I made a cheatsheet here: Should MySQL have its timezone set to UTC?