SUBDATE( )

Use this MySQL function to subtract a date or time interval from the results of a DATE or TIME data type column. It's an alias for DATE_SUB( ).

Syntax

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

SUBDATE(date, INTERVAL value type)
SUBDATE(date days)

Explanation

Use this function to subtract a date or time interval from the results of a DATE or TIME data type column. It's an alias for DATE_SUB( ). If a negative value is given, the interval specified is added instead of subtracted. This is equivalent of ADDDATE( ). See the table under DATE_ADD( ) for a list of intervals permitted.

Examples

SELECT SUBDATE(NOW( ), 1) AS 'Yesterday',
SUBDATE(NOW( ), INTERVAL -1 DAY) AS 'Tomorrow';

+---------------------+---------------------+
| Yesterday           | Tomorrow            |
+---------------------+---------------------+
| 2008-05-09 16:11:56 | 2008-05-11 16:11:56 |
+---------------------+---------------------+

As of version 4.1 of MySQL, when subtracting days, you can just give the number of days for the second argument (i.e., just 1 instead of INTERVAL 1 DAY).