Question

If you need your web application to translate between timezones on a per-user basis, why not use TIMESTAMP across the board for all date/time fields? Consider that TIMESTAMP values are stored in UTC and converted to the timezone set for the connection when retrieved.

I have asked this question on IRC, read the MySQL documentation, searched Google extensively, and asked my co-workers, and I have yet to find a compelling reason to not use TIMESTAMP.

Note: I understand TIMESTAMP has a limited range of 1970 - 2038; that is not going to be an issue in my case. Also, I am using PHP with MySQL.

Was it helpful?

Solution

DATETIME is for arbitrary dates and times that you utilize in your data.

TIMESTAMP is for when you want the time to be automatically updated. If you want to know when the row was inserted/updated, use a TIMESTAMP.

Also, keep in mind that a TIMESTAMP is only stored in UTC -- it is converted to the local timezone of the server before it is transmitted back as part of a query.

In your case, you're better off using a DATETIME. If you're worried about UTC, that's fine -- just create your dates in UTC rather than using the local time. Use UTC_TIMESTAMP.

OTHER TIPS

I think your answer is here:

I understand TIMESTAMP has a limited range of 1970 - 2038; that is not going to be an issue in my case.

I would be careful making assumptions about the longevity of projects especially when it comes to database schemas. Databases have a tendency to remain in place and in use long after the applications that used them have gone away.

Randalpho's answer is wrong on many facts!

Timestamps do not need to be automatically updated on creation OR updates.

Also, timestamps are translated to the CLIENT's local time, not the serever's.

Just look at the MySQL docs for datetime.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top