jeffreyveon
jeffreyveon

Reputation: 13830

What timezone does MySQL's NOW() follow

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

Upvotes: 14

Views: 15796

Answers (3)

Cem Kalyoncu
Cem Kalyoncu

Reputation: 14603

As far as I know its the system clock is returned. Check for your system's time zone. I you connect MySQL locally (like from PHP) time zones will not matter for MySQL, I prefer handling them in PHP.

Upvotes: 0

Alex Martelli
Alex Martelli

Reputation: 882023

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.

Upvotes: 24

Jon Skeet
Jon Skeet

Reputation: 1501586

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. The value is expressed in the current time zone.

Now "the current time zone" can mean different things:

  • The system time zone
  • A time zone specified for the MySQL server in general
  • A connection-specific time zone

More details are in the 5.1 time zone documentation.

(The 5.4 docs look the same for these bits. Obviously consult the docs for the version you're running for the best possible information.)

Upvotes: 13

Related Questions