Export (0) Print
Expand All

DATEADD

SQL Server 2000

Returns a new datetime value based on adding an interval to the specified date.

Syntax
DATEADD ( datepart , number, date ) 
Arguments
datepart
Is the parameter that specifies on which part of the date to return a new value. The following table lists the dateparts and abbreviations recognized by Microsoft® SQL Server™ 2000 Windows® CE Edition (SQL Server CE).
Datepart Abbreviations
year yy, yyyy
quarter qq, q
month mm, m
dayofyear dy, y
day dd, d
week wk, ww
hour hh
minute mi, n
second ss, s
millisecond ms
number
Is the value used to increment datepart. Is an expression of the exact numeric or approximate numeric data type categories, or types that can be implicitly converted to float. If you specify a value that is not an integer, the fractional part of the value is discarded. For example, if you specify day for datepart and 1.75 for number, date is incremented by 1.
date
Is an expression that returns a value that can be implicitly converted to datetime, or is a Unicode character string in a date format. For more information about specifying dates, see datetime in Data Types.

If you specify only the last two digits of the year, values less than or equal to the last two digits of the value of the two digit year cutoff configuration option are in the same century as the cutoff year. Values greater than the last two digits of the value of this option are in the century that precedes the cutoff year. For example, if two digit year cutoff is 2049 (default), 49 is interpreted as 2049 and 2050 is interpreted as 1950. To avoid ambiguity, use four-digit years.

Return Types

datetime

Examples

The following example adds two months to the order date for A. Datum Corporation.

CREATE TABLE MyOrders (OrderID int IDENTITY(100, 1) PRIMARY KEY, CompanyName nvarchar(50), OrderDate datetime)
INSERT INTO MyOrders (CompanyName, OrderDate) VALUES ('A. Datum Corporation', GETDATE())
SELECT DATEADD(month, 2, OrderDate) FROM MyOrders

Show:
© 2014 Microsoft