MySQL time plus and minus function

Source: Internet
Author: User

When performing some scheduled tasks, such as monthly closing, and encountering cross-year cross-month situations, I think it is more reliable to use the SQL statement to select the time, so we can understand the function of the next time plus minus.

There are two such functions, one plus one minus

Date_add ()     adds a specified time interval to a date date_sub ()     subtracts a specified time interval from a date

Take another look at the parameters

Date_sub (Date,interval expr type)

They all have two parameters, one is time, the other is the time interval of the change.

Like the day before the current time.

Select 1 Day);

The type can also be

Microsecondsecondminutehour  Day WEEK MONTH QUARTER  Year Second_microsecondminute_microsecondminute_secondhour_microsecondhour_secondhour_minuteday_microsecondday_ Secondday_minuteday_houryear_month

Date_add () Add a specified time interval to a date
Date_sub () Subtract a specified time interval from a date

MySQL time plus and minus function

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.