I'm using PHP/MySQL and I've always used DATETIME to store created and updated values, but I'm thinking there may be a better way.

Should I be using TIMESTAMP instead, and if so, why?

Comments

possible duplicate of datetime vs timestamp?

Written by OMG Ponies

Accepted Answer

The documentation states:

TIMESTAMP values are converted from the current time zone to UTC for storage, and converted back from UTC to the current time zone for retrieval. (This occurs only for the TIMESTAMP data type, not for other types such as DATETIME.) By default, the current time zone for each connection is the server's time. The time zone can be set on a per-connection basis, as described in Section 9.6, “MySQL Server Time Zone Support”. As long as the time zone setting remains constant, you get back the same value you store. If you store a TIMESTAMP value, and then change the time zone and retrieve the value, the retrieved value is different from the value you stored. This occurs because the same time zone was not used for conversion in both directions. The current time zone is available as the value of the time_zone system variable.

So you may want to use TIMESTAMP if you want your date/time stored in UTC instead of in the current time zone.

This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki