Dateadd in sqlserver

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.