DatePart

concerns

You can use the DatePart function to evaluate a date and return a specific time interval. For example, you can use DatePart to calculate the day of the week.

 

Syntax

DatePart(Interval, Date [, FirstDayOfWeek [, FirstWeekOfYear] ])

Return value

Type

Description

Long

Number of time intervals

Parameter

Use

Name

Type

Passing

Description

Required

Interval

String

ByVal

See below

Required

Date

Double

ByVal

The date to be evaluated

Optional

FirstDayOfWeek

Variant

ByVal

Determines the first day of week

Optional

FirstWeekOfYear

Variant

ByVal

Determines the first week of year

Interval determines the time interval to return. The following values can be specified for Interval:

 

Interval

Description

yyyy

Year

q

Quarter

m

Month

y

Day of the year

d

Day

w

Weekday

ww

Week

h

Hour

n

Minute

s

Second

 

You can use the optional FirstDayOfWeek parameter to define the first day of the week.

 

FirstDayOfWeek

Description

1

Sunday (= Default value)

2

Monday

3

Tuesday

4

Wednesday

5

Thursday

6

Friday

7

Saturday

 

The optional FirstWeekOfYear parameter determines the first week of the year, which by default is defined as the week in which January 1 is located. The following definitions are possible here:

 

FirstWeekOfYear

Description

1

Week of January 1

2

Week in which at least four days of the new year are

3

first full week of the new year

 

Example:

 

Dim Part As Long

Part := DatePart("m", DateSerial(1999, 5, 31)) # retrieves 5

Part := DatePart("ww", DateSerial(1999, 5, 31)) # retrieves 22 (die 22th week)