Table of Contents

    How to Use the DATEADD() Function in SQL Server: A Complete Guide

    How to Use the DATEADD() Function in SQL Server: A Complete Guide

    Syntax:

    
    DATEADD (datepart, NumberToAdd, date)
    

    DATEADD (datepart, NumberToAdd, date) - Returns the DateTime, after adding specified NumberToAdd, to the datepart specified of the given date.

    DatePart Abbreviations
    year yy, yyyy
    quarter qq, q
    month mm, m
    dayofyear dy, y
    day dd, d
    week wk, ww
    weekday dw
    hour hh
    minute mi, n
    second ss, s
    millisecond ms
    microsecond mcs
    nanosecond ns
    TZoffset tz
    ISO_WEEK isowk, isoww

    Code:

    
    Select DateAdd(DAY, 20, '2012-08-30 19:45:31.793') 
     
    Select DateAdd(DAY, -20, '2012-08-30 19:45:31.793') 
     
    

    Output:

    The above code will produce the following result-

    
    2012-09-19 19:45:31.793
    2012-08-10 19:45:31.793