Returns the newDatetimeValue.
Syntax
Dateadd( Datepart, Number, Date)
Parameters
Datepart
Is a parameter that specifies which part of the date should be returned to the new value. The following table lists the dates and abbreviations recognized by Microsoft SQL Server.
Date |
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 used to addDatepart. If you specify a value that is not an integer, the fractional part of the value is discarded. For exampleDatepartSpecifyDay, IsNumberSpecify1.75, ThenDateIt will increase by 1.
Date
YesDatetimeOrSmalldatetimeValue or date format string expression. For more information about the specified date, see datetime and smalldatetime.
If you only specify the last two digits of the year, the number of the last two digits smaller than or equal to the value of the "two-digit year deadline" configuration option is in the same century as the end year. The last two-digit number greater than the value of this option is in the century before the end of the century. For example, ifTwo digit year cutoffIs 2049 (default), then 49 is interpreted as 2049,2050 is interpreted as 1950. To avoid blurring, use a four-digit year.
Return type
ReturnDatetime,However, ifDateThe parameter isSmalldatetime,ReturnSmalldatetime.
Example
In this examplePubsA list of the time structures of titles in the database. This time structure indicates the current release date plus 21 days.
Use pubsgoselect dateadd (Day, 21, pubdate) as timeframefrom titlesgo
The following is the result set:
Timeframe --------------------------- Jul 3 1991 12: 00 amjun 30 1991 12: 00 amjul 21 1991 12: 00 amjul 13 1991 12: 00 amjun 30 1991 12: 00 amjul 9 1991 12: 00 Ammar 14 1997 5: 09 pmjul 21 1991 12: 00 amjul 3 1994 12: 00 Ammar 14 1997 5: 09 pmnov 11 1991 12: 00 amjul 6 1991 12: 00 amoct 26 1991 12: 00 amjul 3 1991 12: 00 amjul 3 1991 12: 00 amnov 11 1991 12: 00 amjul 3 1991 12: 00 amjul 3 1991 am (18 row (s) affected)