DATEADD (Transact-SQL)
DATEADD adds a specified number interval to a datepart of a specified date and returns the resulting date.
Syntax
DATEADD ( datepart , number , date )
datepart – Date part abbreviation (e.g., year, month, day).
number – Integer value representing the number of datepart units to add. Can be negative.
date – The starting date (datetime, smalldatetime, date, datetime2, datetimeoffset).
Parameters
Parameter | Description |
---|---|
datepart | Abbreviation of the part of the date to add. See Datepart. |
number | Number of datepart units to add. Positive values add, negative subtract. |
date | Expression that returns a date value. |
Return Value
Returns a datetime
(or appropriate) value with the added interval. If date
is NULL
, the result is NULL
.
Examples
Basic usage
SELECT DATEADD(year, 1, '2023-04-15'); -- Returns 2024-04-15
Adding months to a datetime
SELECT DATEADD(month, 6, GETDATE()) AS SixMonthsLater;
Subtracting days
SELECT DATEADD(day, -10, '2023-01-01'); -- Returns 2022-12-22