Skip to content

DatePart ​

Returns a Variant (Integer) containing the specified part of a given date.

Syntax: DatePart ( interval, date [, firstdayofweek [, firstweekofyear ]] )

interval
required String expression that is the interval of time to return. See Interval settings.
date
required Variant (Date) value to evaluate.
firstdayofweek
optional A VbDayOfWeek constant specifying the first day of the week. Defaults to vbSunday.
firstweekofyear
optional A VbFirstWeekOfYear constant specifying the first week of the year. Defaults to vbFirstJan1.

Interval settings ​

SettingDescription
yyyyYear
qQuarter
mMonth
yDay of year
dDay
wWeekday
wwWeek
hHour
nMinute
sSecond

firstdayofweek settings ​

ConstantValueDescription
vbUseSystem0NLS API setting.
vbSunday1Sunday (default).
vbMonday2Monday.
vbTuesday3Tuesday.
vbWednesday4Wednesday.
vbThursday5Thursday.
vbFriday6Friday.
vbSaturday7Saturday.

firstweekofyear settings ​

ConstantValueDescription
vbUseSystem0NLS API setting.
vbFirstJan11Week in which January 1 occurs (default).
vbFirstFourDays2First week that has at least four days in the new year.
vbFirstFullWeek3First full week of the year.

The firstdayofweek argument affects calculations that use the "w" and "ww" interval symbols.

If date is a date literal, the specified year becomes a permanent part of that date. If date is enclosed in double quotation marks and the year is omitted, the current year is inserted each time the expression is evaluated.

If the Calendar property setting is Gregorian, the supplied date must be Gregorian. If the calendar is Hijri, the supplied date must be Hijri. The returned date part is in the time period units of the current calendar.

Example ​

This example takes a date and, using the DatePart function, displays the quarter of the year in which it occurs.

vb
Dim TheDate As Date
TheDate = InputBox("Enter a date:")
MsgBox "Quarter: " & DatePart("q", TheDate)

See Also ​

twinBASIC and LOGO copyright of "WaynePhillipsEA" author