Time type in MySQL Datetime,date,time,year,timestamp small knowledge points

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.