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

dateadd1

The dateadd1 function is used to modify the date value by the specified delta according to the specified unit datepart.

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

Syntax

dateadd1(string date, bigint delta, string datepart)

Parameters

Table 1 Parameter descriptions

Parameter

Mandatory

Type

Description

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

delta

Yes

BIGINT

The modification magnitude.

datepart

Yes

STRING

The time unit for modification.

The datepart parameter supports extended date formats: year, month or mon, day, and hour.

  • yyyy indicates year.
  • mm indicates month.
  • dd indicates day.
  • hh indicates hour.
  • mi indicates minute.
  • ss indicates second.

Return Values

Returns a date value of type STRING.

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

Example Code

Returns 2023-08-15 17:00:00 after one day is added.

select dateadd1( '2023-08-14 17:00:00', 1, 'dd');

Returns 2025-04-14 17:00:00 after 20 months are added. Month overflow causes the year to increase by 2.

select dateadd1('2023-08-14 17:00:00', 20, 'mm');

Returns 2023-09-14 17:00:00.

select dateadd1('2023-08-14 17:00:00', 1, 'mm');

Returns 2023-09-14.

select dateadd1('2023-08-14', 1, 'mm');

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

select dateadd1(getdate(),-1,'dd');

Returns NULL.

select dateadd1(date '2023-08-14', 1, null);