MySQL acquisition date (day before, someday)

Source: Internet
Author: User

Day of acquisition:

SELECT curdate ();

Mysql> SELECT curdate ();
+------------+
| Curdate () |
+------------+
| 2013-07-29 |
+------------+

Get the current date:

Mysql> Select Now ();
+---------------------+
| Now () |
+---------------------+
| 2013-07-29 22:10:40 |
+---------------------+

Get the day before:

Mysql> Select Date_sub (curdate (), Interval 1 day);
+------------------------------------+
| Date_sub (Curdate (), Interval 1 day) |
+------------------------------------+
| 2013-07-28 |
+------------------------------------+

In parentheses, the day before today, if the number of days before the statistics, the parentheses in the ' 1 ' is changed to the corresponding days. If you want to count months or years, change the day directly to month or year

Year prior to acquisition:

Mysql> SELECT Year (Date_sub (Curdate (), INTERVAL 1 day));
+------------------------------------------+
| Year (Date_sub (Curdate (), INTERVAL 1 day)) |
+------------------------------------------+
| 2013 |
+------------------------------------------+

Example of the Date_sub () function:

Today is May 20, 2013.

Date_sub (' 2012-05-25 ', Interval 1 day) says 2012-05-24
Date_sub (' 2012-05-25 ', Interval 0 day) says 2012-05-25
Date_sub (' 2012-05-25 ', interval-1 day) says 2012-05-26
Date_sub (' 2012-05-31 ', interval-1 day) says 2012-06-01
Date_sub (Curdate (), Interval 1 day) represents 2013-05-19
Date_sub (Curdate (), Interval-1 day) represents 2013-05-21
Date_sub (Curdate (), Interval 1 month) represents 2013-04-20
Date_sub (Curdate (), Interval-1 month) represents 2013-06-20
Date_sub (Curdate (), Interval 1 year) represents 2012-05-20
Date_sub (Curdate (), Interval-1 year) represents 2014-05-20

MySQL acquisition date (day before, someday)

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.