


DatePart
| interval
| is a string expression that is the interval of time you use to return.
|
| date
| is the date you want to inspect or the name of a Date/Time field.
|
| firstweekday
| is an integer that specifies the first day of the week; 1=Sunday, 2=Monday,
etc. firstweek is an integer that specifies the first week of the year. It can be any of
the following:
0=Use the First Week setting in the Options dialog box 1=Start on January 1 (default) 2=Start with the first four-day week 3=Start with the first full week |
You can use the DatePart function to inspect a date and return a specific interval of time. For example, you can use DatePart to calculate the day of the week for an order’s ship date or the current hour.
The exact value returned by
DatePart can depend on the settings of the First Weekday and First Week options in the Options dialog box (View menu) or by the values of the firstweekday or firstweek arguments. For example, if you set firstweekday to Monday, then DatePart returns the value 3 (Wednesday) for the date 11/3/93:
Const SUNDAY = 1, MONDAY = 2
Dim DayOfWeek As Integer
DayOfWeek = DatePart("w", "11/3/93", MONDAY)
If you change firstweekday to Sunday, then DatePart would return 4 for the same date.
The following table lists the valid time periods and their interval values.
| Time period
| interval
|
| Year
| yyyy
|
| Quarter
| q
|
| Month
| m
|
| Day of year
| y
|
| Day
| d
|
| Weekday
| w
|
| Week
| ww
|
| Hour
| h
|
| Minute
| n
|
| Second
| s
|
Example
This example calculates which day of the week New Year's Eve falls on:
FindDay = DatePart("w", "31-Dec")
This example determines the calendar quarter in which an order was placed:
FindQtr = DatePart("q", Forms![Orders]![Order Date])