Skip to main content
Version: V1.3.0

SUBDATE

Declaration​

SUBDATE(date,INTERVAL expr unit)

SUBDATE(expr,days)

Description​

When SUBDATE() is called with the second parameter in the form of INTERVAL, it is a synonym for DATE_SUB(), returning the value of the date or datetime date after subtracting 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​

SELECT DATE_SUB('2022-01-02', INTERVAL 31 DAY);
+-----------------------------------------+
| DATE_SUB('2022-01-02', INTERVAL 31 DAY) |
+-----------------------------------------+
| 2021-12-02 |
+-----------------------------------------+
1 row in set (0.001 sec)

SELECT SUBDATE('2022-01-02', INTERVAL 31 DAY);
+----------------------------------------+
| SUBDATE('2022-01-02', INTERVAL 31 DAY) |
+----------------------------------------+
| 2021-12-02 |
+----------------------------------------+
1 row in set (0.001 sec)

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 (0.001 sec)