DATE_SUB
The DATE_SUB function is used to calculate the date after adding or subtracting a certain number of days to a specified date. This function returns a new date value. If the calculation result exceeds the system date range, it returns null.
Syntax
Parameters
date
: The date that needs to be calculated, type is date.int
: The number of days to add or subtract, type is integer.
Return Result
- Returns a new date value, type is date.
Example
The following example shows how to use the DATE_SUB function for date calculation:
-
Calculate the date 3 days before May 31, 2020:
-
Calculate the date one day after February 29, 2020.
Please note that the DATE_SUB function only applies to columns with date types. If the input parameter type is incorrect, an error will be returned.