VBScript DatePart Function

Definition and Usage

The DatePart function can return the specified part of a 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 between date1 and date2 to be calculated.

The following values can be used:

  • yyyy - Year
  • q - Quarter
  • m - Month
  • y - Day of the year
  • d - Day
  • w - Day of the week
  • ww - Week
  • h - Hours
  • n - Minutes
  • s - Seconds
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:

  • 0 = vbUseSystemDayOfWeek - Use the system language support (NLS) API settings.
  • 1 = vbSunday - Sunday (default)
  • 2 = vbMonday - Monday
  • 3 = vbTuesday - Tuesday
  • 4 = vbWednesday - Wednesday
  • 5 = vbThursday - Thursday
  • 6 = vbFriday - Friday
  • 7 = vbSaturday - Saturday
firstweekofyear

Optional. Specifies the first week of the year.

The following values can be used:

  • 0 = vbUseSystem - Use the system language support (NLS) API settings.
  • 1 = vbFirstJan1 - From the week containing January 1st (default).
  • 2 = vbFirstFourDays - From the first week of the year with at least four days.
  • 3 = vbFirstFullWeek - From the first full week of the new year.

Beispiel

Beispiel 1

d = #2/10/96 16:45:30#
document.write(DatePart("yyyy",d)) 'Ausgabe: 1996'
document.write(DatePart("m",d)) 'Ausgabe: 2'
document.write(DatePart("d",d)) 'Ausgabe: 10'
document.write(DatePart("h",d)) 'Ausgabe: 16'
document.write(DatePart("n",d)) 'Ausgabe: 45'
document.write(DatePart("s",d)) 'Ausgabe: 30'
document.write(DatePart("q",d)) 'Ausgabe: 1, Februar ist das 1. Quartal'
document.write(DatePart("y",d)) 'Ausgabe: 41, 10. Februar ist der 41. Tag des Jahres 1996.'
document.write(DatePart("ww",d)) 'Ausgabe: 6, 10. Februar ist die 6. Woche des Jahres 1996.'
document.write(DatePart("w",d)) 'Ausgabe: 7, 10. Februar ist der 6. Woche des Jahres 1996 der 7. Tag (Samstag).'