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

date_sub(date, int)

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:

  1. Calculate the date 3 days before May 31, 2020:

    SELECT date_sub('2020-05-31', 3);
      2020-05-28
  2. Calculate the date one day after February 29, 2020.

    SELECT date_sub('2020-02-29', 1);
     2020-02-28

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.