DateAdd() in Classic ASP

Use DateAdd() in Classic ASP to add or subtract days, months, years, weeks, hours, minutes or seconds from an existing Date. It returns a new Date value; the original variable is unchanged.

Start with a fixed date so the result is easy to verify:

<%
Dim startDate, nextDate
startDate = DateSerial(2024, 1, 31)
nextDate = DateAdd("m", 1, startDate)
Response.Write Month(nextDate) & "/" & Day(nextDate) & "/" & Year(nextDate)
%>

Output: 2/29/2024. February 2024 has 29 days, so adding one month to January 31 adjusts to the last valid day in February.

On this page — Show page sectionsHide page sections

Syntax and parameters

DateAdd(interval, number, date)
ParameterMeaning
intervalUnit such as "d", "m" or "yyyy"
numberPositive values add time; negative values subtract it
dateExisting Date value, such as Date or DateSerial(...)

DateAdd interval codes

CodeUnitExample
yyyyYearDateAdd("yyyy", 1, d)
qQuarterDateAdd("q", 1, d)
mMonthDateAdd("m", 2, d)
y, d, wCalendar dayDateAdd("d", 7, d)
wwWeekDateAdd("ww", 2, d)
hHourDateAdd("h", 1, d)
nMinuteDateAdd("n", 30, d)
sSecondDateAdd("s", 45, d)
Important: DateAdd("w", ...) adds ordinary calendar days, not Monday-to-Friday business days. The "m" code means months; minutes use "n".

Add five years to today

The original lesson used the current server date and added five years. This example keeps that behavior, so the displayed result depends on when you run it:

<%
Dim d_today, d_added
d_today = Date
Response.Write "Today: " & d_today & "<br>"
d_added = DateAdd("yyyy", 5, d_today)
Response.Write "Five years later: " & d_added
%>

Add six months

<%
Dim d_today, d_added
d_today = Date
d_added = DateAdd("m", 6, d_today)
Response.Write d_added
%>

For stable arithmetic, use a fixed input with DateSerial(); when using Date the result varies with the current server date.

Subtract days and months

<%
Dim d
d = DateSerial(2024, 3, 31)
Response.Write DateAdd("d", -7, d) & "<br>"
Response.Write DateAdd("m", -1, d)
%>

The first expression moves back seven days; the second moves to February 29, 2024. Display formatting depends on locale.

Leap years and calendar rollovers

The original demonstration added 32 days to January 28. Compare a leap year and a non-leap year:

<%
Dim leapDate, commonDate
leapDate = DateAdd("d", 32, #1/28/2004#)
commonDate = DateAdd("d", 32, #1/28/2003#)
Response.Write Month(leapDate) & "/" & Day(leapDate) & "/" & Year(leapDate) & "<br>"
Response.Write Month(commonDate) & "/" & Day(commonDate) & "/" & Year(commonDate)
%>
2/29/2004
3/1/2003

Add weeks and minutes

<%
Dim deadline
deadline = DateSerial(2026, 11, 13) + TimeSerial(9, 0, 0)
Response.Write DateAdd("ww", 2, deadline) & "<br>"
Response.Write DateAdd("n", 45, deadline)
%>

Here "ww" advances by calendar weeks and "n" advances by minutes. Neither operation converts between time zones.

Practical example: expiry after 30 days

<%
Dim issuedOn, expiresOn
issuedOn = DateSerial(2026, 11, 13)
expiresOn = DateAdd("d", 30, issuedOn)
Response.Write "Expires: " & Year(expiresOn) & "-" & _
  Right("0" & Month(expiresOn), 2) & "-" & Right("0" & Day(expiresOn), 2)
%>
Expires: 2026-12-13

Use a stored date value for actual expiry comparisons, and account for time zones if your application has users in different regions.

Common mistakes

Check for a misspelled interval, an invalid date input, or a confusion between month ("m") and minute ("n"). Avoid assuming that a month has exactly 30 days or that "w" means workdays.

Frequently asked questions

Does DateAdd() change the original date?

No. It returns a new date value; assign the result to a variable to keep it.

What happens when I add a month to January 31?

The result is adjusted to the last available day of February, including February 29 in leap years.

How do I count the number of days between two dates?

Use DateDiff("d", startDate, endDate) instead.

Can I subtract a month?

Yes. Pass a negative number, for example DateAdd("m", -1, myDate).

Back to top ↑


ASP Home






✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer