devxlogo

Return Date Parts With VBScript

Return Date Parts With VBScript

Browsers Targeted: Internet Explorer 4+

You can retrieve any component of a date (either as a string, a hash-delimited date expression, or a date object) with the DatePart() function in Visual Basic. As with both DateAdd() and DateDiff, you specify an interval token and the function returns the part of the date given by the token.

For example, suppose that you wanted to retrieve the current day of the week (with Sunday being 1). The code for this retrieval is quite simple:

  

The token intervals are given here:

Interval TokenInterval MeaningFunction Call
N/ANowNow
yyyyYearDatePart(“yyyy”,Now)
qQuarterDatePart(“q”,Now)
mMonthDatePart(“m”,Now)
yDay in YearDatePart(“y”,Now)
wweekdayDatePart(“w”,Now)
wwweek in yearDatePart(“ww”,Now)
hHourDatePart(“h”,Now)
nMinuteDatePart(“n”,Now)
sSecondDatePart(“s”,Now)
See also  Monetize TikTok For Your Business
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