SQL Server DATEADD()Function


SQL DatesSQL Server Date Functions

Definition and Usage

The DATEADD() function adds or subtracts a specified time interval from a date.

Syntax

DATEADD(datepart,number,date)

The date parameter is a valid date expression. number is the number of intervals you wish to add; for future times, this number is positive, for past times, this number is negative.

The datepart parameter can be one of the following values:

datepart Abbreviation
year yy, yyyy
Quarter qq, q
month mm, m
Day of year dy, y
day dd, d
week wk, ww
Week dw, w
Hour hh
Minute mi, n
second ss, s
Millisecond ms
Microsecond mcs
Nanosecond ns


Example

Suppose we have the following "Orders" table:

OrderId ProductName OrderDate
1 Jarlsberg Cheese 2008-11-11 13:23:44.657

Now, we want to add 45 days to "OrderDate", so that we can find the payment date.

We use the following SELECT statement:

SELECT OrderId,DATEADD(day,45,OrderDate) AS OrderPayDate
FROM Orders

Result:

OrderId OrderPayDate
1 2008-12-26 13:23:44.657


SQL DatesSQL Server Date Functions Other Extensions