Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What timezone does MySQL's NOW() follow

Tags:

sql

mysql

Does MySQL's NOW() follow the system's timezone or some standard like GMT or UTC?

like image 598
jeffreyveon Avatar asked Sep 18 '09 16:09

jeffreyveon


People also ask

What timezone does now () use?

It's in the current time zone. From the 5.1 docs: Returns the current 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.

What timezone does MySQL use?

By default, the time zone for a MySQL DB instance is Universal Time Coordinated (UTC). You can set the time zone for your DB instance to the local time zone for your application instead.

How do I find my Postgres time zone?

You can check all of the supported timezone names by using the following query: select * from pg_timezone_names; Let's exit our psql session, and reenter into it again.


1 Answers

Per the docs, the rules are complicated, but mostly boil down to "current session's timezone" (which defaults to system timezone):

The current session time zone setting affects display and storage of time values that are zone-sensitive. This includes the values displayed by functions such as NOW() or CURTIME(), and values stored in and retrieved from TIMESTAMP columns. Values for TIMESTAMP columns are converted from the current time zone to UTC for storage, and from UTC to the current time zone for retrieval.

Of course you can use UTC_TIMESTAMP() if you need UTC specifically.

like image 160
Alex Martelli Avatar answered Oct 13 '22 14:10

Alex Martelli