Extract date parts with DatePart() in Classic ASP

DatePart() extracts a requested component from a VBScript Date value, such as the month, year, weekday or week number.

Syntax

DatePart(interval, date[, firstdayofweek[, firstweekofyear]])

Get the current month

Dim d_today
d_today = Now
Response.Write DatePart("m", d_today)

Get a year

Response.Write DatePart("yyyy", #9/10/2003#)

The output is 2003.

Dedicated Day(), Month() and Year() functions

Year(#10/15/2003#)

Returns 2003.

Month(#10/15/2003#)

Returns 10.

Day(#10/15/2003#)

Returns 15.

Week calculations: if you use w or ww, specify firstdayofweek and firstweekofyear when your application requires a particular calendar convention instead of relying on defaults.

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