VBScript DatePart Function
Complete VBScript Reference Manual
The DatePart function returns a specified part of a given date.
Syntax
DatePart(interval,date[,firstdayofweek[,firstweekofyear]])
| Parameters | Description |
|---|---|
| interval | Required. The time interval to return.
The following values can be used: |
The following values can be used:
- 0 = vbUseSystemDayOfWeek - use the Regional Language Support (NLS) API setting
- 1 = vbSunday - Sunday (default)
- 2 = vbMonday - Monday
- 3 = vbTuesday - Tuesday
- 4 = vbWednesday - Wednesday
- 5 = vbThursday - Thursday
- 6 = vbFriday - Friday
- 7 = vbSaturday - Saturday
The following values can be used:
- 0 = vbUseSystem - use the Regional Language Support (NLS) API setting
- 1 = vbFirstJan1 - start with the week in which January 1 falls (default)
- 2 = vbFirstFourDays - start with the first week that has at least four days in the new year
- 3 = vbFirstFullWeek - start with the first full week in the new year
Example
Example 1
Get the month from a date:
The example above produces the following output:
2
Try it »
Example 2
Get the month we are currently in:
The example above produces the following output:
document.write(DatePart("m",Now()))
Try it »
Example 3
Get the hour:
The example above produces the following output:
document.write(DatePart("h",Now()))
Try it »
Complete VBScript Reference Manual