MySQL supports five date and time types: date, time, year, timestamp, and datetime
1. Date type
Support range is from 1000-01-01 to 9999-12-31
When the data is previewed, it is displayed in YYYY-MM-DD format, such as 2021-03-12
2. Datetime type
The supported range is from 1000-01-01 00:00:00.000000 to 9999-12-31 23:59:59.999999
When the data is previewed, it is displayed in the format of YYYY-MM-DD hh:mm:ss[.fraction], for example, 2021-03-12 23:34:40
3. Timestamp type
The support range is from 1970-01-01 00:00:01.000000 to 2038-01-19 03:14:07.999999
4. Time type
The support range is from -838:59:59.000000 to 838:59:59.000000
5. Year type
Year, number, range from 1901 to 2155, or 0000
Among them, the timestamp and datetime types both support setting the default value CURRENT_TIMESTAMP and updating the default value ON UPDATE CURRENT_TIMESTAMP
CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ts` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`dt` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8