Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I want to make it so calls to NOW() and CURDATE() in MySQL queries return the date in UTC. How do I make this happen without going through and changing all queries that use these functions?

like image 550
Chad Johnson Avatar asked Jun 03 '09 21:06

Chad Johnson


People also ask

What is the output displayed by NOW () and Curdate () function?

The NOW() function gives current datetime as a timestamp while CURDATE() gives only current date, not time. A demo of CURDATE().

Is MySQL now UTC?

In MySQL, the 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 the usage of the function i.e. in a string or numeric context.

How do I change timezone in MySQL?

In MySQL the CONVERT_TZ() returns a resulting value after converting a datetime value from a time zone specified as the second argument to the time zone specified as the third argument. This function returns NULL when the arguments are invalid. A datetime. A time zone which will be converted to to_tz.

What is the difference between Curdate and now in MySQL?

What is the difference between MySQL NOW() and CURDATE() function? As the name suggests CURDATE() function will return the current date. In simple words, we can say that it would return only the date not time. In contrast, NOW() function will return current date and time.


1 Answers

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.

like image 126
Chad Johnson Avatar answered Sep 28 '22 06:09

Chad Johnson