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 interval between date1 and date2. The following values can be used:
|
date | Required. The date expression to be calculated. |
firstdayofweek |
Optional. Defines the number of days in a week, i.e., the day of the week. The following values can be used:
|
firstweekofyear |
Optional. Defines the first week of the year. The following values can be used:
|
Παράδειγμα
Παράδειγμα 1
d = #2/10/96 16:45:30# document.write(DatePart("yyyy",d)) 'Εξαγωγή: 1996 document.write(DatePart("m",d)) 'Εξαγωγή: 2 document.write(DatePart("d",d)) 'Εξαγωγή: 10 document.write(DatePart("h",d)) 'Εξαγωγή: 16 document.write(DatePart("n",d)) 'Εξαγωγή: 45 document.write(DatePart("s",d)) 'Εξαγωγή: 30 document.write(DatePart("q",d)) 'Εξαγωγή: 1, ο Φεβρουάριος είναι η 1η σεζόν document.write(DatePart("y",d)) 'Εξαγωγή: 41, 10 Φεβρουαρίου είναι η 41η ημέρα του 1996. document.write(DatePart("ww",d)) 'Εξαγωγή: 6, 10 Φεβρουαρίου είναι η 6η εβδομάδα του 1996. document.write(DatePart("w",d)) 'Εξαγωγή: 7, 10 Φεβρουαρίου είναι η 6η εβδομάδα της 7η ημέρα (Σάββατο) του 1996.