devxlogo

Calculate the Difference Between Dates With VBScript

Calculate the Difference Between Dates With VBScript

Browsers Targeted: Internet Explorer 4+

If you want to find out the number of days, weeks, months, etc. between two dates, you can take advantage of the VBScript 5.0 DateDiff() function. This function lets you specify two dates and an interval token to retrieve a count of the number of that interval between the two dates.

For example, suppose that you wanted to know the number of days from January 1, 2000. The code for this is quite simple:

  

The token intervals are given as follows:

Interval TokenInterval MeaningFunction Call
N/ANowNow
yyyyYearDateDiff(“yyyy”,#1/1/2000#,Now)
qQuarterDateDiff(“q”,#1/1/2000#,Now)
mMonthDateDiff(“m”,#1/1/2000#,Now)
yDay in YearDateDiff(“y”,#1/1/2000#,Now)
wweekdayDateDiff(“w”,#1/1/2000#,Now)
wwweek in yearDateDiff(“ww”,#1/1/2000#,Now)
hHourDateDiff(“h”,#1/1/2000#,Now)
nMinuteDateDiff(“n”,#1/1/2000#,Now)
sSecondDateDiff(“s”,#1/1/2000#,Now)
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist