MySQL time type summary

  • If it is used to represent the year, month and day, it is usually represented by date.
  • If it is used to represent the year, month, day, hour, minute, and second, it is usually represented by datetime.
  • If it is used to represent hours, minutes and seconds, it is usually represented by time.
  • If you need to frequently insert or update the date to the current system time, it is usually represented by timestamp, and the timestamp value is returned as'YYYY-MM-DD HH:mm:ss
  • If only the year is displayed, it can be represented by YEAR, which occupies less space than DATE

The difference between timestamp and datetime

1. The time range supported by timestamp is smaller, and the datetime range is larger.

2. The first timestamp column in the table is automatically set to the system time. If you insert null in a timestamp column, the column value will be automatically set to the current date and time. When inserting or updating a row but not explicitly assigning a value to the timestamp column, it will also automatically set the value of the column to the current date and time. When the inserted value exceeds the value range, MySQL considers the value to overflow and fills it with "0000-00-00 00:00:00".

3. The attribute of timestamp is greatly affected by MySQL version and server sqlmode.

Guess you like

Origin blog.csdn.net/qq_36138652/article/details/105374144