Updated on 2026-11-06 GMT+08:00

date_add

The date_add function is used to calculate the date obtained by incrementing the start_date by the specified number of days.

To obtain a date with a specified offset from the current date, it can be used together with current_date or getdate.

Note that the date_add function has the opposite logic to date_sub.

Syntax

date_add(string startdate, int days)

Parameters

Table 1 Parameter descriptions

Parameter

Mandatory

Type

Description

start_date

Yes

DATE

or

STRING

The start date.

Supports the following formats:

  • yyyy-mm-dd
  • yyyy-mm-dd hh:mi:ss
  • yyyy-mm-dd hh:mi:ss.ff3

days

Yes

BIGINT

The number of days to add.

  • If days is greater than 0, days are added.
  • If days is less than 0, days are subtracted.
  • If days equals 0, 0 days are added and the date remains unchanged.
  • If the days value is NULL, NULL is returned.

Return Values

Returns a date value of type DATE, in the format yyyy-mm-dd.

  • If start_date is not of type DATE or STRING, an error is returned with the message "data type mismatch".
  • If start_date is of type DATE or STRING but does not conform to the input format for date values, NULL is returned.
  • If the start_date value is NULL, NULL is returned.
  • If the days value is NULL, NULL is returned.

Example Code

  • Example 1
    select date_add('2023-02-28 00:00:00', 1);

    Returns 2023-03-01. Adding one day results in a date beyond the last day of February of that year, so the actual value is the first day of the next month.

  • Example 2
    select date_add(date '2023-02-28', -1);

    Returns 2023-02-27. Subtracts one day.

  • Example 3
    select date_add('2023-02-28 00:00:00', 20);

    Returns 2023-03-20.

  • Example 4
    select date_add(getdate(),-1);

    Assuming the current time is 2023-08-14 16:00:00, returns 2023-08-13.

  • Example 5
    select date_add('2023-02-28 00:00:00', null);

    Returns NULL.