Menu

1 / 2

MySQL DATETIME vs TIMESTAMP: Which to Use, and What Converting a Column Does to Its Values

DEV Community: mysql·Son Tran·6 days ago
#PMfmO63e
#devtomysql#devto#dev#datetime#timestamp
Long article (1775 words) — no AI summary yet.
Reading 0:00
15s threshold

Disclosure: I build Schemity , a desktop ERD tool - this post is from our blog and uses it for the examples.

TL;DR: Use DATETIME for MySQL timestamps and have the application write UTC: it holds years 1000 to 9999 and stores exactly what it is given. TIMESTAMP converts through the session time zone and refuses anything after 2038-01-19 03:14:07 UTC, which already rules it out for expiry dates and contracts. Converting a column between the two rewrites the table, and in either direction the session time zone decides what the values become.

A MySQL TIMESTAMP column cannot hold a date after January 2038 and changes meaning with each connection's time zone, so DATETIME filled with UTC by the application is the safer default. TIMESTAMP looks like the more correct type, because MySQL converts it to UTC for you, but it ends in January 2038, it shifts every value with the connection's time zone, and it refuses some local times outright.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.