Returns a date to which a specified time interval has been added.
||A string expression code that specifies the interval type you want to add, specified as a quoted string. The table of available codes is shown below.
||A numeric expression that is the number of intervals you want to add. The numeric expression can either be positive to add intervals, or negative to subtract intervals.
||Variable name or literal representing the date to which the specified interval is added (or subtracted). The date can optionally have a time component; if not specified, the time defaults to 00:00:00.
function returns the calculated date in the following format:
Leading zeros are displayed. The year is displayed as four digits.
argument can have the following values:
||Day of Year (this adds the specified number of days to date; same as d).
||Weekday (this adds the specified number of days to date; same as d).
||Week (this adds the specified number of weeks to date).
||Minute (note this is n, not m)
You can use the DateAdd
function to add or subtract a specified interval from a date. For example, you can use DateAdd
to calculate a date 30 days from a given date, or a date 100 hours earlier than a given date. To add days to date
, you can use Day of Year ("y"), Day ("d"), or Weekday ("w").
function computes the varying number of days in different months (including leap years), and avoids returning an invalid date.
The following example adds one of each date interval unit to January 31, 2005:
NewDay = DateAdd("d",1,"31-Jan-2005")
NewWDay = DateAdd("w",1,"31-Jan-2005")
NewWeek = DateAdd("ww",1,"31-Jan-2005")
NewMonth = DateAdd("m",1,"31-Jan-2005")
NewQuarter = DateAdd("q",1,"31-Jan-2005")
NewYDay = DateAdd("y",1,"31-Jan-2005")
NewYear = DateAdd("yyyy",1,"31-Jan-2005")
In the case of adding one month to 31-Jan-2005, DateAdd
returns 02/28/2005, not 02/31/2005. If date is 31-Jan-2004, it returns 02/29/2005, because 2004 is a leap year. If the calculated date would precede the year 100, an error occurs.
The following example adds a time interval large enough to increment the specified date:
NewHour = DateAdd("h",27, "31-Jan-2005")
NewMin = DateAdd("n",1545, "31-Jan-2005")
NewSec = DateAdd("s",91522, "31-Jan-2005")
Note that the values returned contain both a date and a time component.