Share via


6.1.2.4.1.3 DatePart

Function Declaration

 Function DatePart(Interval As String, 
                   BaseDate As Variant, 
                   Optional FirstDayOfWeek 
                         As VbDayOfWeek = vbSunday, 
                   Optional FirstWeekOfYear 
                         As VbFirstWeekOfYear = vbFirstJan1 
                   ) 

Parameter

Description

Interval

String data value (section 2.1) that specifies the interval of time to extract from BaseDate.

BaseDate

Date data value from which the interval is extracted.

FirstDayOfWeek

A constant that specifies the first day of the week. If not specified, Sunday is assumed. See section 6.1.1.7.

FirstWeekOfYear

A constant that specifies the first week of the year. If not specified, the first week is assumed to be the week in which January 1 occurs.

Runtime Semantics.

§ Returns a Integer data value containing the specified part of a given date

§ The Interval argument is interpreted according to this table:

 

Interval Data Value

Meaning

"yyyy"

Year

"q"

Quarter

"m"

Month

"y"

Day of year

"d"

Day

"w"

Weekday

"ww"

Week

"h"

Hour

"n"

Minute

"s"

Second

Any other data value

Raise Error 5, "Invalid procedure call or argument"

 

§ The interpretation of the Interval data value is not case sensitive.

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

§ For BaseDate, 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 Arabic calendar. For example, if the current calendar is Hijri and the date part to be returned is the year, the year value is a Hijri year.