Other ASP Sections
Date & Time
Functions
Request
Response
Add / Subtract from Dates
Summary:
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 9th September 1984 would display 10/09/1984.
<% = DateAdd("m", 1, "09/09/1984") %>By changing the interval we can instead change add one day. This example would display tomorrows date as 05/02/2012, 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 03/02/2012, this time.
<% = DateAdd("d", -1, Date()) %>
