SQL Server DATEADD () function

Source: Internet
Author: User
Definition and usage

The DATEADD () function adds or removes the specified time interval in the date.

Syntax
DATEADD(datepart,number,date)

DateA parameter is a valid date expression.NumberIs the number of intervals you want to add. For the future time, this number is a positive number, and for the past time, this number is a negative number.

DatepartParameters can be the following values:

 

Datepart Abbreviations
Year Yy, yyyy
Quarter Qq, q
Month Mm, m
Day of the year Dy, y
Day Dd, d
Week Wk, ww
Week Dw, w
Hours Hh
Minutes Mi, n
Seconds Ss, s
Millisecond MS
Subtle Mcs
Nanoseconds Ns

 

Instance

Suppose we have the following "Orders" table:

OrderId ProductName OrderDate
1 'Computer' 16:25:46. 635

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

We use the following SELECT statement:

SELECT OrderId,DATEADD(day,2,OrderDate) AS OrderPayDateFROM Orders

Result:

OrderId OrderPayDate
1 16:25:46. 635
Related Article

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.