This tutorial explains how to use the MySQL SUBDATE function with syntax and examples.
The MySQL SUBDATE function returns a date after which a certain time/date interval has been subtracted.
The syntax for the SUBDATE function in MySQL is:
OR
The date to which the interval should be subtracted.
The number of days to subtract from date (second syntax).
The value of the time/date interval that you wish to subtract. You can specify positive and negative values for this parameter (first syntax).
The unit type of the interval such as DAY, MONTH, MINUTE, HOUR, and so on. It can be one of the following (first syntax):
unit | Compatibility |
---|---|
MICROSECOND | 4.1.1+ |
SECOND | 3.2.3+ |
MINUTE | 3.2.3+ |
HOUR | 3.2.3+ |
DAY | 3.2.3+ |
WEEK | 5+ |
MONTH | 3.2.3+ |
QUARTER | 5+ |
YEAR | 3.2.3+ |
SECOND_MICROSECOND | 4.1.1+ |
MINUTE_MICROSECOND | 4.1.1+ |
MINUTE_SECOND | 4.1.1+ |
HOUR_MICROSECOND | 4.1.1+ |
HOUR_SECOND | 4.1.1+ |
HOUR_MINUTE | 3.2.3+ |
DAY_MICROSECOND | 4.1.1+ |
DAY_SECOND | 3.2.3+ |
DAY_MINUTE | 3.2.3+ |
DAY_HOUR | 3.2.3+ |
YEAR_MONTH | 3.2.3+ |
The SUBDATE function can be used in the following versions of MySQL:
Let's look at some MySQL SUBDATE function examples and explore how to use the SUBDATE function in MySQL.
For example: