1, datetime,date,time,year Four types of values, can be entered manually, you can also call the function to get the value
① manual input, in the following format:
DateTime "2016-6-22 14:09:30"
Date "2016-6-22"
Time "14:09:30"
Year "2016"
As mentioned above, when manually entered, you can directly enter the string as above, note the need to quote. Where the delimiter in the date and time (the short horizontal line "-", the time of the colon ":"), can be replaced by other symbols, such as "2016/6/22 14/9/30"
② use the function to get the value, you can use the now () function to get the current time
2, timestamp type of value, can not input, the database will be automatically populated
Example code:
/* CREATE TABLE */
Mysql> Create Tabletime_table ( -Dtdatetime, -d date, -t time, -Y Year, -Tstimestamp - ); Query OK,0Rows Affected (0.05sec)
/* View table structure */mysql> desctime_table;+-------+-----------+------+-----+-------------------+-----------------------------+|Field|Type| Null | Key | Default |Extra|+-------+-----------+------+-----+-------------------+-----------------------------+|Dt| datetime |YES| | NULL | ||D|Date|YES| | NULL | ||T|Time|YES| | NULL | ||Y| Year(4)|YES| | NULL | ||Ts| timestamp |NO| | Current_timestamp | on Update Current_timestamp |+-------+-----------+------+-----+-------------------+-----------------------------+5Rowsinch Set(0.01sec)
/* Manually inserting data, TS data is Null*/mysql> Insert intoTime_table (Dt,d,t,y,ts)Values(" .-6- A One: $: -"," ./6/ A"," One: $: -"," .",NULL); Query OK,1Row affected (0.01sec)
/* Insert data manually, no data is provided for TS */mysql> Insert intoTime_table (Dt,d,t,y)Values(" .-6- A One: $: -"," ./6/ A"," One: $: -"," ."); Query OK,1Row affected (0.00sec)
/* Use the Now () function to provide data, enter data manually for the Y field, and do not provide data for TS */mysql> Insert intoTime_table (Dt,d,t,y)Values(Now (), now (), now (),' .'); Query OK,1Row affected,1Warning (0.00sec)
/* Insert data manually, date time separator to "/", still no data provided for TS */mysql> Insert intoTime_table (Dt,d,t,y)Values(" ./6/ A -/Ten/ -"," ./6/ A"," -:Ten: -"," ."); Query OK,1Row affected (0.00sec)
/* View Data */mysql> Select * fromtime_table;+---------------------+------------+----------+------+---------------------+|Dt|D|T|Y|Ts|+---------------------+------------+----------+------+---------------------+| .- .- A One: $: - | .- .- A | One: $: - | . | .- .- A One: -:xx || .- .- A One: $: - | .- .- A | One: $: - | . | .- .- A One: -: to || .- .- A -: -: Wu | .- .- A | -: -: Wu | . | .- .- A -: -: Wu || .- .- A -:Ten: - | .- .- A | -:Ten: - | . | .- .- A -: One: - |+---------------------+------------+----------+------+---------------------+4Rowsinch Set(0.00Sec
Time type in MySQL Datetime,date,time,year,timestamp small knowledge points