Difference between DATETIME and TIMESTAMP in MySQL
Start your free 7-days trial now!
MySQL's DATETIME
and TIMESTAMP
data types are very similar in that both are used to store date and time information, however, each data type does have its own advantages which are discussed below.
TIMESTAMP
The
TIMESTAMP
type in MySQL is often used to track changes to records such as keeping track of the last modified time of a record.This is possible by setting a column to auto-update.
The reason the
TIMESTAMP
type is suited for this is because everything is stored in UTC (Coordinated Universal Time), which allows for tracing back to a single point in time.
DATETIME
The
DATETIME
type does not necessarily allow us to trace back to a single point in time as we do not necessarily know the timezone for theDATETIME
value.However, the advantage of the
DATETIME
type is that the supported range of values'1000-01-01 00:00:00'
to'9999-12-31 23:59:59'
is much larger than that ofTIMESTAMP
'1970-01-01 00:00:01'
UTC to'2038-01-09 03:14:07'
UTC.This makes it more suited for storing date and time information that is likely to fall outside the range of
TIMESTAMP
(e.g. storage of Date of Birth information).