DATEADD

Syntax

Description of the illustration dateadd.gif

time_unit::=

Description of the illustration time_unit.gif

Purpose

DATEADD adds or subtracts a specified time interval from a date or timestamp value.

Semantics

DATEADD takes three arguments:

The return type of the output matches the input type of datetime.

Note, if the input is of type DATE, and value evaluates to a number less than a SECOND (for example, 1 MILLISECOND, 9 MICROSECOND, 10 NANOSECOND), the added integer is ignored, because DATE does not store fractional seconds.

Examples

Examples : When Time Unit is MONTH

The following example subtracts one month from the timestamp. It keeps the same time and time zone offset, and moves the date from April 30, 2023 back to March 30, 2023.

SELECT DATEADD(MONTH, -1, TIMESTAMP '2023-04-30 11:24:54 +01:00');

Result:

2023-03-30 11:24:54 +01:00

The following example adds one month to the timestamp. Because May has a 30th day, the day stays 30. The time and timezone offset stay the same.

SELECT DATEADD(MONTH, 1, TIMESTAMP '2023-04-30 11:24:54 +01:00');

Result:

2023-05-30 11:24:54 +01:00

The following example adds one month to February 28 2023.

SELECT DATEADD(MONTH, 1, TIMESTAMP '2023-02-28 11:24:54 +01:00');

Result:

2023-03-28 11:24:54 +01:00

Example 2: DATEADD behavior for Non_Existent Time

The timestamp is just before the 2025 spring Daylight Savings Time jump in America/Los Angeles. So adding one real hour to 01:59:59 lands at 03:59:59 because the 02:00 hour does not exist locally on that day.

SELECT DATEADD(
  HOUR,
  1,
  TO_TIMESTAMP_TZ(
     '09-MAR-2025 01:59:59 AMERICA/LOS_ANGELES PST',
     'DD-MON-YYYY HH24:MI:SS TZR TZD'
    )
 );

Result:

2025-03-09 03:59:59 America/Los_Angeles PDT

Example 3: When Integer has Fractional Parts

The 1.9 value is rounded up to 2, so 2 years are added.

SELECT DATEADD(YEAR, 1.9, DATE '2023-02-02');

Result:

2023-02-02