DateAdd SQL Function

The DateAdd() function takes three (3) arguments and returns calculated date or datetime, it can work with local date time or UTC date time, the format of date time is wide and it attempts to parse the value using DateTime.TryParse.

Syntax for DateAdd(Date time Value , How much + or - , Modifier) . The Date time should be valid value, second argument is positive or negative number and third is string with one of the following values:

Modifier Explanation
years Number of years added/subtracted to the date
months Number of months added/subtracted to the date
days Number of days added/subtracted to the date
hours Number of hours added/subtracted to the date
minutes Number of minutes added/subtracted to the date
seconds Number of seconds added/subtracted to the date
millisecond Number of seconds (and fractional seconds) added/subtracted to the date
ticks Number of ticks to add or subtract, see DateTime.Now.Ticks and TimeSpan.TicksPerDay in .NET on MSDN.


/* Following will add 4 days in today's date. */ 
SELECT DateAdd(GetDate(), +4, 'Days'); /* Following will subtract 4 days in today's date accepts negative value. */ SELECT DateAdd(GetDate(), -4, 'Days'); /* Following will add 4 hours in today's date. */ SELECT DateAdd(GetDate(), 4, 'Hours'); /* Following will add 15 minutes using .Net TimeSpan Ticks. */ SELECT DateAdd(GetDate(), 9000000000, 'Tick');