Declaration
SUBDATE(date,INTERVAL expr unit)
SUBDATE(expr,days)
Description
When SUBDATE() is called with the second parameter in INTERVAL form, it is a synonym for DATE_SUB(), used to return the value of the date and time 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