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)