DATETIME vs. TIMESTAMP
Shlomi blogged over the weekend about DATETIME vs. TIMESTAMP, and hit all the major differences, except one extremely important one that very few people know about (in my opinion).
Coincidentally, last week's OurSQL podcast was about time, and included the most important difference between TIMESTAMP vs. DATETIME:
TIMESTAMP is stored, transparently to you and me, in UTC. DATETIME is not. The best way to explain this is with an illustration -- go to a MySQL instance on a machine whose system time zone you can change, and run the following example:
CREATE TABLE time_test (dt datetime, ts timestamp);
INSERT INTO time_test (dt, ts) VALUES (NOW(), NOW());
SELECT dt,ts from time_test;
Now, shut down MySQL, change the system time zone, start up MySQL again, and run:
SELECT dt,ts from time_test;
Archives
- May 2012
- April 2012
- March 2012
- February 2012
- January 2012
- December 2011
- November 2011
- October 2011
- September 2011
- August 2011
- July 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
- January 2011
- December 2010
- November 2010
- October 2010
- September 2010
- November 2009
- March 2008
- November 2007
- October 2007


Comments
+1
It's also worth considering what declaring an index on a timestamp column to be unique asserts: the users will make no time zone changes that could cause duplicate values to be present. MySQL currently returns only one of the matching rows if a time zone change causes duplicate values to be present and the unique index is used. James Day, MySQL Principal Support Engineer, Oracle
Reply