DATEADD
This function adds a specified number value (as a signed integer) to a specified datepart of an input date value, and then returns that modified value.
The DATEADD function simply allows you to add or subtract the specified number of units of time to a specified date/time value.
Syntax
DATEADD (datepart , number , date)
Arguments
datepart - The part of date to which DATEADD adds an integer number. This table lists all valid datepart arguments.
- datepart - Abbreviations
- year - yy, yyyy
- quarter - qq, q
- month - mm, m
- dayofyear - dy, y
- day - dd, d
- week - wk, ww
- weekday - dw, w
- hour - hh
- minute - mi, n
- second - ss, s
- millisecond - ms
- microsecond - mcs
- nanosecond - ns
number - An expression that can resolve to an int that DATEADD adds to a datepart of date. DATEADD accepts user-defined variable values for number. DATEADD will truncate a specified number value that has a decimal fraction. It will not round the number value in this situation.
date - An expression that can resolve to one of the values like date, datetime, datetimeoffset, datetime2, smalldatetime, time.
Example
-- to add 5 days to September 1, 2020 the function would be
DATEADD(DAY, 5, '9/1/2020')
-- to subtract 5 months from September 1, 2020 the function would be
DATEADD(MONTH, -5, '9/1/2020')
DATEADD() Function and Examples
- Add 30 days to a date SELECT DATEADD(DD,30,@Date)
- Add 3 hours to a date SELECT DATEADD(HOUR,-3,@Date)
- Subtract 90 minutes from date SELECT DATEADD(MINUTE,-90,@Date)
- Check out the chart to get a list of all options.