MySQL time date function type and use

Source: Internet
Author: User

--MySQL time date function type and use
--1, Day (), month (), year ()--Returns the number of days, months, and years of the specified date;
Select Day (Curdate ()) as ' date ' from dual;
Select Month (Curdate ()) as ' month ' from dual;
Select year (Curdate ()) as ' years ' from dual;

--2, now (), Current_timestamp (), localtime (), Localtimestamp () Take the time when the statement was executed
--Sysdate () takes a dynamic actual time
Select Current_timestamp (), SLEEP (3), localtime (), Localtimestamp (), now (), Curdate (), Sysdate () from DUAL;


Select Timediff (' 13:25:20 ', ' 10:20:30 ') from DUAL; --two time periods to subtract the resulting time
Select DateDiff (' 2014-02-01 ', ' 2012-05-12 ') from DUAL; --Returns the number of days between two dates
Select Date_add (' 2016-05-24 ', INTERVAL 5 years) from dual;--adds a specified time interval to the date
Select Date_sub (' 2016-05-24 ', INTERVAL 5 years) from the dual;--function subtracts the specified time interval from the date
Select Date_format (Curdate (), '%y-%m-%d ') from the dual--function is used to display date/time data in different formats.

MySQL time date function type and use

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.