How do I make MySQL's NOW() and CURDATE() functions use UTC?

Finally found what I was looking for...

In my.cnf,

[mysqld_safe]
timezone = UTC

I was putting this option under [mysqld], and mysql was failing to start.

Calling "SET time_zone='+0:00';" on every page load would also work, but I don't like the idea of calling that query on every single page load.


Set your server's clock to UTC. No really.

If you can do it, do do it.

One of the biggest headaches is "cron" jobs etc, running in local time zone, this means that some cron jobs will get missed once a year, and all the rest run at a different time GMT for half the year (I'm assuming you're in a time zone which has daylight saving time here).

MySQL has time zone support, but it's crazy and messed up. Don't use it if you don't have to. Just set your server's clock to UTC and time will start working how it should.

I know that changing the server clock is a major change for any managed system, and you may have a large number of servers and services which could be affected, but please, try to do it anyway. The QA work may be significant, but try.


UTC_TIMESTAMP()

Returns the current UTC date and time as a value in 'YYYY-MM-DD hh:mm:ss' or YYYYMMDDhhmmss.uuuuuu format, depending on whether the function is used in a string or numeric context.

UTC_DATE()

Returns the current UTC date as a value in 'YYYY-MM-DD' or YYYYMMDD format, depending on whether the function is used in a string or numeric context.

UTC_TIME()

Returns the current UTC time as a value in 'hh:mm:ss' or hhmmss.uuuuuu format, depending on whether the function is used in a string or numeric context.

MySQL reference: https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_utc-timestamp