MySQL time and date

Source: Internet
Author: User
Datetime occupies 8 bytes to display the date and display the time yyyy-mm-dd hh: mm: SS display range 1000-01-01 00:00:00 ---- 9999-12-31 23:59:59 available format/01/01 00 + 01 + 102011010100011011/01/01/00 @ 01@10mysql5.5 versions earlier date type cannot be accurate to microsecond level date occupies 3 bytes display date display range: 1000-01-01----9999-12-31 timestamp occupies 4 bytes 1970 10 10 80001----2038-01-19 03: 14: 07 The timestamp and datetime display results are the same but the display range is different. You can set the default value in the timestamp format when creating a table, if datetime does not update the table, you can set the columns of the timestamp type to automatically update to the current time-838: 59: 59 ---- 838: 59: 59 year can use year (2) and year (4) time-related functions Now current_timestamp sysdate 1. Now and current_timestamp are the same 2. The sysdate function returns the time when the current function is executed, and the time when the now function returns the SQL statement. Time addition and subtraction If the target year is a leap month, the system automatically adds or subtracted one day. Date_add (date, interval expr unit) date_sub (date, interval expr unit) date_add (now (), interval 1 day) unit can be the following data: yearmonthdayweekhourminutesecondmicrosecond date_format () function, the function is to format and print the date as required by the user. If the query condition is used, we recommend that you use the time index. Select Date_format (now (), '% Y % m % D ') As datetime;

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.