ASP Vbscript DateAdd function with Date Intervals

Updated on 22 Feb 2012,
Published on 14 Aug 2008

Vbscript DateAdd function of date time function series is used in classic ASP to get the date value based on addition of specified date interval to the given date value. Vbscript DateAdd function returns the date to which specified value for the interval of date part has been added. You can specify the date interval such as months, days or years etc.

Classic ASP VbScript Date Functions Examples:

You can see the live samples and examples of Classic ASP VbScript Date functions from the following links:

Syntax for Vbscript DataAdd Function

DateAdd(interval, number, date)

Vbscript DateAdd function accepts the 3 types of parameters as shown in above syntax:

1. interval: first parameter accepts the date part name as string value. Following are the supported date interval types:

d - day
m – month
yyyy – year
y – day of year
w – week of month
ww – week of year
q – quarter

2. number: second parameter accepts number value that is to be added in the specified date interval.

3. date: third parameter accepts the date value to which specified number is to be added. 

Examples of ASP Vbscript DateAdd function using Date Intervals 

Examples to add date interval using DateAdd function
<%
' add 10 days to the specified date value
Response.Write(DateAdd("d", 10, "Jan 1,2008") & "<br />")

' add 10 months to the specified date value
Response.Write(DateAdd("m", 10, "Jan 1,2008") & "<br />")

' add 10 quarters (3 * 10 months) to the specified date value
Response.Write(DateAdd("q", 10, "Jan 1,2008") & "<br />")

' add 10 years to the specified date value
Response.Write(DateAdd("yyyy", 10, "Jan 1,2008") & "<br />")

' add 10 week days to the specified date value
Response.Write(DateAdd("w", 10, "Jan 1,2008") & "<br />")

' add 10 weeks to the specified date value
Response.Write(DateAdd("ww", 10, "Jan 1,2008") & "<br />")
%>
Examples to subtract date interval using DateAdd function
<%
' subtract 10 days from the secified date value
Response.Write(DateAdd("d", -10, "Jan 1,2008") & "<br />")

' subtract 10 months from the secified date value
Response.Write(DateAdd("m", -10, "Jan 1,2008") & "<br />")

' subtract 10 quarters (3 * 10 months) from the specified date value
Response.Write(DateAdd("q", -10, "Jan 1,2008") & "<br />")

' subtract 10 years from the secified date value
Response.Write(DateAdd("yyyy", -10, "Jan 1,2008") & "<br />")

' subtract 10 week days from the secified date value
Response.Write(DateAdd("w", -10, "Jan 1,2008") & "<br />")

' subtract 10 weeks from the secified date value
Response.Write(DateAdd("ww", -10, "Jan 1,2008") & "<br />")
%>

Vbscript DateAdd function can also be used to add the time interval to the given time value. Click here to learn the use of ASP Vbscript DateAdd function with Time Intervals.

Output:

You can see the output of above discussed code from the following link:

DateAdd Function with Date Intervals

Continue to next tutorial: ASP Vbscript DateDiff Function using Date Intervals to learn the functionality of DateDiff function.

0 Responses to "ASP Vbscript DateAdd function with Date Intervals"
Leave a Comment
* required
* required
* will not be published
* optional
* hint: http://www.example.com
  • Subscribe via Email