Syntax
SUBDATE(date,INTERVAL expr unit)
SUBDATE(expr,days)
Purpose
When you call the SUBDATE() function by using INTERVAL as the second argument, the function is a synonym for DATE_SUB() and returns the value of date minus expr.
For more information about the INTERVAL and unit arguments, see DATE_ADD.
SUBDATE(expr,days) allows you to use an integer value for days. In this case, it returns the result of subtracting the specified number of days 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