Applicable scene:
The DATEADD() function adds or subtracts the specified time interval from the date.
Syntax format:
DATEADD(datepart,number,date)
field description : date parameter is a valid date expression. number is the number of intervals you wish to add;
Available datepart parameter values:
datepart | abbreviation |
---|---|
year | yy, yyyy |
Quarterly | qq, q |
month | mm, m |
Day of the year | dy, y |
day | dd, d |
week | wk, ww |
week | dw, w |
hour | hh |
minute | my n |
second | ss, s |
millisecond | ms |
subtle | mcs |
Nanosecond | ns |
Examples:
select getdate();-display system time
select dateadd(yy,2,getdate());-add 2 years to the system time
select dateadd(mm,2,getdate());-add 2 months to the system time
select dateadd(dd,2,getdate());-add 2 days in the system time
select dateadd(ww,2,getdate());-add 2 weeks to the system time
select dateadd(hh,2,getdate());-add 2 hours to the system time
select dateadd(mi,2,getdate());-add 2 minutes to the system time