The difference between DATETIME and TIMESTAMP in MySQL is described in the following document:
DateTime
A date and time combination. The supported range is '2017-01-01 00:00:00 'to '2017-12-31 23:59:59 '.
MySQL displays DATETIME values in 'yyyy-MM-DD HH: MM: SS' format, but allows you to assign values to DATETIME columns using either strings or numbers.
TimeStamp
A timestamp. The range is '2017-01-01 00:00:00 'to partway through the year 1970.
A timestamp column is useful for recording the date and time of an INSERT or UPDATE operation.
The first TIMESTAMP column in a table is automatically set to the date and time of the most recent operation if you don't assign it a value yourself.
You can also set any TIMESTAMP column to the current date and time by assigning it a NULL value.
Now let's start a specific comparison:
DATETIME, 8 bytes, value range: "1000-01-01 00:00:00 -- 9999-12-31 23:59:59"
The corresponding Java type is java. SQL. Timestamp.
During the INSERT or UPDATE operation, the system does not automatically modify the value. you cannot set the default value. you must manually INSERT a required field. we recommend that you use new ()
MySql formatted data by YYYY-MM-DD HH: MM: SS, allowed to be submitted in string and Number format
Eg: insert into time_table (CreateDate) values ('2017-06-09 15:01:01 ')
Or insert into time_table (CreateDate) values ('20140901 ')
TIMESTAMP. the number of bytes is 4 and the value range is "197001000000001--20108119111407"
The corresponding Java type is java. SQL. Timestamp.
During the INSERT or UPDATE operation (without manual assignment), the system automatically updates and inserts the current system time. the default value is CURRENT_TIMESTAMP ()
When you submit a manual assignment to NULL, the assignment will also be assigned to the current system time, and the error will be filled with 0
When using TIMESTAMP, be sure to pay attention to its time range (see above ).