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 Token Interval Meaning Function Call
N/A Now Now
yyyy Year DateDiff(“yyyy”,#1/1/2000#,Now)
q Quarter DateDiff(“q”,#1/1/2000#,Now)
m Month DateDiff(“m”,#1/1/2000#,Now)
y Day in Year DateDiff(“y”,#1/1/2000#,Now)
w weekday DateDiff(“w”,#1/1/2000#,Now)
ww week in year DateDiff(“ww”,#1/1/2000#,Now)
h Hour DateDiff(“h”,#1/1/2000#,Now)
n Minute DateDiff(“n”,#1/1/2000#,Now)
s Second DateDiff(“s”,#1/1/2000#,Now)
See also  The Importance of Data Security in Hospitality
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