Syntax
SUBDATE(date,INTERVAL expr unit)
SUBDATE(expr,days)
Purpose
When SUBDATE() is called with the second argument in the form of INTERVAL, it is a synonym for DATE_SUB() and returns the value of the date or datetime date minus expr.
For information about the INTERVAL and unit parameters, see DATE_ADD.
SUBDATE(expr,days) allows the use of an integer value for days. In this case, it is interpreted as the number of days to subtract from the date or datetime expression expr.
Examples
obclient> SELECT DATE_SUB('2022-01-02', INTERVAL 31 DAY);
+-----------------------------------------+
| DATE_SUB('2022-01-02', INTERVAL 31 DAY) |
+-----------------------------------------+
| 2021-12-02 |
+-----------------------------------------+
1 row in set
obclient> SELECT SUBDATE('2022-01-02', INTERVAL 31 DAY);
+----------------------------------------+
| SUBDATE('2022-01-02', INTERVAL 31 DAY) |
+----------------------------------------+
| 2021-12-02 |
+----------------------------------------+
1 row in set
obclient> SELECT SUBDATE('2022-01-02 12:00:00', 31);
+------------------------------------+
| SUBDATE('2022-01-02 12:00:00', 31) |
+------------------------------------+
| 2021-12-02 12:00:00 |
+------------------------------------+
1 row in set
