1. Syntax:
Dateadd (datepart, number, date)
2. Parameters
-
-
Datepart
-
Yes andIntegerThe date part of the Number Addition. The following table lists all valid datepart parameters. The user-defined equivalent variable is invalid.
Datepart |
Abbreviations |
Year |
YY,Yyyy |
Quarter |
Qq,Q |
Month |
Mm,M |
Dayofyear |
Dy,Y |
Day |
Dd,D |
Week |
WK,WW |
Weekday |
DW,W |
Hour |
HH |
Minute |
Mi,N |
Second |
SS,S |
Millisecond |
MS |
Microsecond |
MCS |
Nanosecond |
NS |
-
-
Number
-
-
Is an expression that can be parsed into an int that is added to datepart of date. User-Defined variables are valid.
If you specify a decimal value, the decimal number is truncated without rounding.
-
-
Date
-
-
Is an expression that can be parsedTime,Date,Smalldatetime,Datetime,Datetime2OrDatetimeoffsetValue. Date can be an expression, column expression, user-defined variable, or string text. If the expression is a string, it must be resolved toDatetimeValue. To avoid uncertainty, use a four-digit year. For information about the two-digit year, see the two digit year cutoff option.
3. Example: return the order of the last three months. Consider the specific date.
View code 1 Select * From orderst Where Adddate > Dateadd (m, - 3 , Getdate () Order by adddate
Return the order of the first three months. If the date is not considered, it starts from the first day.
CodeAs follows:
View code 1 Select * From orderst Where Datediff (M, adddate, getdate ()) <= 3 Order by adddate
4. display today's order
Select * From orderst where adddate> convert (varchar, getdate (), 112) order by adddate
1. Refer to: msdn -- dataadd