There are several times in MySQL: Date, time, DateTime, timestamp, year
MySQL data type meaning
Date only stored date, ' 2018-07-12 '
Time is stored only seconds and minutes, ' 09:51:02 '
DateTime storage Month day minute minute, ' 2018-07-12 09:51:02 '
Timestamp storage date and minute, ' 2018-07-12 09:51:02 ' Note: This type of field time will automatically refresh as other field values are modified
Year only stores years, ' 2018 '
You can do it yourself in the database
Create the test table as follows:
DROP TABLE IF EXISTS' test ';CREATE TABLE' Test ' (' Time ' timeDEFAULT NULL, ' Date ' dateDEFAULT NULL, `datetime`datetime DEFAULT NULL, `timestamp`timestamp NULL DEFAULT NULL on UPDATE Current_timestamp, ` Year` Year(4)DEFAULT NULL) ENGINE=MyISAMDEFAULTCHARSET=UTF8;
Insert a piece of data:
INSERT into datetime timestamp Year VALUES ('2018-07-12 09:51:02'2018-07-12 09:51:02' 2018-07-12 09:51:02'2018-07-12 09:51:02' 2018');
Show below:
It is important to note that the year Type field, when inserting data, can only insert two-bit/four-bit digits, or two-bit/four-bit numeric strings,
Insert a two-digit number:
Less than 70 of the time, save to the database is ' 20** ';
When greater than or equal to 70, save to the database is ' 19** ';
Insert a four-digit number:
Only four digits between 1901--2099 are inserted
These people can test themselves.
Differences between several date and time types in MySQL and their use