MySQL's Date,datetime,timestamp and time data types

Source: Internet
Author: User
Tags date datetime

DateTime types are used when you need to include values for both date and time information. MySQL retrieves and displays the datetime value in the ' yyyy-mm-dd HH:MM:SS ' format, supported by ' 1000-01-01 00:00:00 ' to ' 9999-12-31 23:59:59 '. ("support" means that although earlier values may work, there is no guarantee that they can.) )

The date type has no time part when you only need a date value. MySQL retrieves and displays date values in the ' YYYY-MM-DD ' format, supported by ' 1000-01-01 ' to ' 9999-12-31 '.

The timestamp column type provides a type that you can use to automatically mark an INSERT or update operation with the current date and time.

The time data type represents the times of the day. MySQL retrieves and displays the time value in "HH:MM:SS" format. The range of support is ' 00:00:00 ' to ' 23:59:59 '.

CREATE TABLE SQL

CREATE TABLE ' tb_test ' (  
  ' id ' int () NOT NULL auto_increment,  
  ' date1 ' timestamp not null DEFAULT ' 0000-00-00 00:0 0:00 ' on UPDATE current_tim  
estamp,  
  ' date2 ' date default null,  
  ' date3 ' datetime default NULL,  
  ' time ' Time DEFAULT NULL,  
  PRIMARY KEY (' id ')  
);

Screenshot of Run Effect:

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/database/MySQL/

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.