VBScript DatePart Function
Definition and Usage
The DatePart function can return the specified part of the given date.
Note:The firstdayofweek parameter affects the calculation using the interval symbols 'w' and 'ww'.
Syntax
DatePart(interval,date[,firstdayofweek[,firstweekofyear]])
Parameters | Description |
---|---|
interval |
Required. The unit of time for calculating the time interval between date1 and date2. The following values can be used:
|
date | Required. The date expression to be calculated. |
firstdayofweek |
Optional. Specifies the number of days in a week, i.e., the day of the week. The following values can be used:
|
firstweekofyear |
Optional. Specifies the first week of the year. The following values can be used:
|
Voorbeeld
Voorbeeld 1
d = #2/10/96 16:45:30# document.write(DatePart("yyyy",d)) 'Uitvoer: 1996' document.write(DatePart("m",d)) 'Uitvoer: 2' document.write(DatePart("d",d)) 'Uitvoer: 10' document.write(DatePart("h",d)) 'Uitvoer: 16' document.write(DatePart("n",d)) 'Uitvoer: 45' document.write(DatePart("s",d)) 'Uitvoer: 30' document.write(DatePart("q",d)) 'Uitvoer: 1, februari is het 1e kwartaal' document.write(DatePart("y",d)) 'Uitvoer: 41, 10 februari is de 41e dag van 1996.' document.write(DatePart("ww",d)) 'Uitvoer: 6, 10 februari is de 6e week van 1996.' document.write(DatePart("w",d)) 'Uitvoer: 7, 10 februari is de 6e week van 1996, de 7e dag (zaterdag).'