Dec 01 2012

MySQL datetime vs timestamp

Posted by Gerrit Schimpf in MySQL

Both data types: timespamp and datetime can be used to store a date and a time in a MySQL table. So what are the difference between these two and which one should I use in which cases?

The usual use of timestamps in MySQL is in generall to track changes of record (fields like created, last_changed). If you want to store a specific value you should use a datetime field. In MYSQL 5 and above, 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, and not for other types such as DATETIME.)

http://dev.mysql.com/doc/refman/5.5/en/datetime.html

One Response to “MySQL datetime vs timestamp”

  1. Todd Says:

    Just as a note, MySQL 5.6 expands the familiar auto-assignment of values on TIMESTAMP columns to DATETIME as well. The new functionality also allows multiple columns defined to record the current time on INSERT or DELETE.

    http://mysqlblog.fivefarmers.com/2012/05/29/overlooked-mysql-5-6-new-features-timestamp-and-datetime-improvements/

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


× 5 = five