difference Contrast
Stores
TIMESTAMP
1.4-byte storage (time stamp value was stored in 4 bytes)
2. Value is saved in UTC (It stores the number of milliseconds)
3. Time zone conversion, storage time for the current time zone conversion, retrieval and then converted back to the current time zone.
Datetime
1.8 bytes Storage (8 bytes storage)
2. Actual format storage (Just stores what you have stored and retrieves the same thing for you which have.)
3. Time zone Independent (It has nothing to deal with the TIMEZONE and conversion.)
Summary
Same point
Can be used to represent time
are displayed as strings
Different points
As the name suggests, date represents only the ' yyyy-mm-dd ' form of dates, DateTime represents the date plus time in the form of ' Yyyy-mm-dd HH:mm:ss ', timestamp the same as the datetime display.
Date and DateTime can be expressed as ' 1000-01-01 ' to ' 9999-12-31 ', timestamp because of the 32-bit int type, can represent ' 1970-01-01 00:00:01 ' to ' 2038-01-19 03:14:07 UTC time.
MySQL converts the time to UTC when it stores the timestamp type and then reverts to the current time zone when it is read. If you store a value of timestamp type, and then modify the MySQL time zone, you will get the wrong time when you read the value again. This does not happen in date and DateTime. The
TIMESTAMP type provides automatic update functionality, and you only need to set its default value to Current_timestamp.
The datetime and timestamp are persisted to the second and the milliseconds are ignored except that date is persisted to the day.