- ⌂ Date & Time
- Functions
DATE_SUB()
Subtract a positive or negative amount of time from a date or timestamp.
Prototype
mixed DATE_SUB(mixed $date, INTERVAL integer $amount UNIT)
Parameters
- date - A date (YYYY-MM-DD) or timestamp (YYYY-MM-DD HH:MM:SS).
- amount - A positive or negative number of UNITs to subtract from the date.
- UNIT - One of the following keywords: MICROSECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, QUARTER, YEAR, SECOND_MICROSECOND, MINUTE_MICROSECOND, MINUTE_SECOND, HOUR_MICROSECOND, HOUR_SECOND, HOUR_MINUTE, DAY_MICROSECOND, DAY_SECOND, DAY_MINUTE, DAY_HOUR, YEAR_MONTH.
Return
If a date is provided, the adjusted date string is returned. If a timestamp is provided, the adjusted timestamp string is returned. If there is an error, such as an invalid date, NULL is returned.
Example
SELECT OID, Date, DATE_SUB(Date, INTERVAL 30 DAY) AS DueDate FROM Invoice