DATEADD() Function in SQL Server



The DATEADD() function adds a time/date interval to date and then returns the date.

The time/date interval to add. Can be one of the following values
year, yyyy, yy = Year
quarter, qq, q = Quarter
month, mm, m = month
dayofyear, dy, y = Day of the year
day, dd, d = Day
week, ww, wk = Week
weekday, dw, w = Weekday
hour, hh = hour
minute, mi, n = Minute
second, ss, s = Second
millisecond, ms = Millisecond
  1. SELECT DATEADD(year, 1, '2018/07/20'AS DateAdd;  
  2.   
  3. SELECT DATEADD(month, 1, '2018/07/20'AS DateAdd;  
  4.   
  5. SELECT DATEADD(hour, -2, '2017/08/25 10:10'AS DateAdd;  
  6.   
  7. SELECT DATEADD(n, -2, '2017/08/25 10:10'AS DateAdd;  
  8.   
  9. SELECT DATEADD(ss, -2, '2017/08/25 10:10:40'AS DateAdd;  
 
 
 

0 Comment's

Comment Form