-
The DATE type is used for values that have a date part but no time part . MySQL retrieves and displays DATE values in the format. Supported ranges are 'YYYY-MM-DD' '1000-01-01' '9999-12-31'
-
The DATETIME type is used for values that contain both date and time parts . MySQL retrieves and displays DATETIME values in the format. The supported ranges are: 'YYYY-MM-DD hh:mm:ss' '1000-01-01 00:00:00' '9999-12-31 23:59:59'
-
The TIMESTAMP data type is used for values that contain both date and time parts . TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC. **
The difference and use of datetime and timestamp in MySQL
Similarities between TIMESTAMP and DATETIME:
- Both can be used to represent values that contain both date and time parts: dates of type YYYY-MM-DD HH:MM:SS[.fraction].
Differences between TIMESTAMP and DATETIME:
- The storage methods of the two are different
For TIMESTAMP, it converts the time inserted by the client from the current time zone to UTC (Coordinated Universal Time) for storage. When querying, it is converted into the current time zone of the client and returned .
By default, the current time zone for each connection is the server's time. The time zone can be set on a per connection basis. As long as the timezone setting remains the same, you can return the same value stored.
And for DATETIME, do not make any changes, basically input and output as is .
- The time ranges that the two can store are different
The time range that timestamp can store is: '1970-01-01 00:00:01.000000' to '2038-01-19 03:14:07.999999'.
The time range that datetime can store is: '1000-01-01 00:00:00.000000' to '9999-12-31 23:59:59.999999'.
Reference document: https://dev.mysql.com/doc/refman/5.6/en/datetime.html