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]])
Parameter | Description |
---|---|
interval |
Required. The unit of time interval to be calculated 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, that is, 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:
|
Esempio
Esempio 1
d = #2/10/96 16:45:30# document.write(DatePart("yyyy",d)) 'Output: 1996' document.write(DatePart("m",d)) 'Output: 2' document.write(DatePart("d",d)) 'Output: 10' document.write(DatePart("h",d)) 'Output: 16' document.write(DatePart("n",d)) 'Output: 45' document.write(DatePart("s",d)) 'Output: 30' document.write(DatePart("q",d)) 'Output: 1, febbraio è il primo trimestre.' document.write(DatePart("y",d)) 'Output: 41, 10 febbraio è il 41° giorno del 1996.' document.write(DatePart("ww",d)) 'Output: 6, 10 febbraio è la settimana 6 del 1996.' document.write(DatePart("w",d)) 'Output: 7, 10 febbraio 1996 è il settimo giorno della settimana 6 (sabato).'