Add / Subtract from Dates

It is often necessary to add or subtract values from dates. You can use the DateAdd() function to add or subtract a specified time interval from a date. For example, you can use DateAdd to calculate a date 30 days from today or a time 45 minutes from now. To add days to date, you can use Day of Year ("y"), Day ("d"), or Weekday ("w").

Arguments:

DateAdd(interval, number, date)
  • interval (Required)
    String expression that is the interval you want to add. See Settings section for values.
  • number (Required)
    Numeric expression that is the number of interval you want to add. The numeric expression can either be positive, for dates in the future, or negative, for dates in the past.
  • date (Required)
    Variant or literal representing the date to which interval is added.

Settings:

The interval argument can have the following values:

Setting Description
yyyy Year
q Quarter
m Month
y Day of year
d Day
w Weekday
ww Week of year
h Hour
n Minute
s Second

Examples:

Adding one month to the date 25th June 2006 would display 25/07/2006.

<% = DateAdd("m", 1, "25/06/2006") %>

By changing the interval we can instead change add one day. This example would display tomorrows date as 23/01/2021, by adding in the date function Date() we get today's date.

<% = DateAdd("d", 1, Date()) %>

If you wished to display yesterdays date, you would use the following example. This example would display yesterdays date as 21/01/2021, this time.

<% = DateAdd("d", -1, Date()) %>
Written By: S2H, 25th June 2006

Bookmark

Advertisement