Add the number of days to a certain date and find another date.

Source: Internet
Author: User
Tags add days
How can I add days to the date field, for example,-1-31 plus 2 months,
Please reply. Thank you!

1st answers to this question:

Select dateadd (mm, 2, '2017-1-31 ')

2nd answers to this question:

-- Add the current date to the date of two months:
Select dateadd (mm, 2, getdate ())

3rd answers to this question:
Dateadd
Returns a new datetime value based on a specified date.

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 date and abbreviation recognized by Microsoft & reg; SQL Server & #8482.

Abbreviation of date
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 increase the value of datepart. 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 increased by 1.

Date

Is an expression that returns the datetime, smalldatetime, or date format string. 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, if two digit year cutoff is 2049 (default), 49 is interpreted as 2049,2050 as 1950. To avoid blurring, use a four-digit year.

Return type
Return datetime, but if the date parameter is smalldatetime, return smalldatetime.

4th answers to this question:
Dateadd (date part, plus amount, date value to be operated)

5th answers to this question:
Select getdate ()
Select dateadd (mm, 2, getdate ())


------------------------------------------------------
2007-03-24 21:40:01. 847

(The number of affected rows is 1)


------------------------------------------------------
21:40:01. 847

(The number of affected rows is 1)

6th answers to this question:
Select dateadd (mm, 2, '2017-1-31 ')

7th answers to this question:
Select dateadd (month, 2, '2014-1-31 ')

-- Result
------------------------------------------------------
2007-03-31 00:00:00. 000

(1 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.