SQL Server DATEADD()
Function
Definition and Usage
The DATEADD() function adds or subtracts a specified time interval from a date.
Syntax
The date parameter is a valid date expression. The number is the interval you want to add; this number is positive for future times and negative for past times.
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 |
Weekday | 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" to find the payment date.
We use the following SELECT statement:
Result:
OrderId | OrderPayDate |
---|---|
1 | 2008-12-26 13:23:44.657 |