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)