#### DatePart

##### DatePart(intervalType, inputDateTime, firstDayOfWeek, firstWeekOfYear)

Returns a number that specifies a given part of a given date.

Overloads

- DatePart(intervalType, inputDateTime)
- DatePart(intervalType, inputDateTime, firstDayOfWeek)
- DatePart(intervalType, inputDateTime, firstDayOfWeek, firstWeekOfYear)
- DatePart(intervalType, inputTime)
- DatePart(intervalType, inputTime, firstDayOfWeek)
- DatePart(intervalType, inputTime, firstDayOfWeek, firstWeekOfYear)

Parameters

- intervalType - A String expression that specifies the part of a date to be returned. Possible values can be:

  IntervalType value | Description
  --- | ---
  Yyyy | Extracts the year
  Q | Quarter (the result is 1, 2, 3 or 4)
  M | Month (the result is from 1 to 12)
  Y | Day of year (1 to 365 or 366 in a leap year)
  D | Day part of the date (1 to 31) Year
  W | Day of week (1 to 7 with the result depending on firstDayOfWeek)
  Ww | Week of year (1 to 53 with firstDayOfWeek and firstWeekOfYear determining the exact days of the first calendar week of the year)
  H | Extracts the hour part of the given DateTime (0 to 23)
  N | Minute part (0 to 59)
  S | Second part (0 to 59)

- inputDateTime - The DateTime value whose part will be extracted.
- FirstDayOfWeek - An optional constant used to specify the first day of the week. If not specified, jrSunday will be used.

  Constant | Description
  --- | ---
  jrUseSystem | 0 (Use the current system date)
  jrSunday | 1
  jrMonday | 2
  jrTuesday | 3
  jrWednesday | 4
  jrThursday | 5
  jrFriday | 6
  jrSaturday | 7

- firstWeekOfYear - An optional constant specifying the first week of the year. If not specified, the first week is assumed to be the one in which Jan. 1 occurs (jrFirstJan1).

  Constant | Value | Description
  --- | --- | ---
  jrUseSystem | 0 | Start with week in which system date occurs
  jrFirstJan1 | 1 | Start with week in which January 1 occurs (default)
  jrFirstFourDays | 2 | Start with the first week that has at least four days in the new year
  jrFirstFullWeek | 3 | Start with first full week of the year

Examples

- `DatePart("d", ToDateTime(1999,8,15))` - Returns 15.
- `DatePart("m", ToDateTime(1999,8,15))` - Returns 8.
- `DatePart("n", ToDateTime(1999,8,15,10,35,0))` - Returns 35.
- `DatePart("q", ToDateTime(1999, 9,29))` - Returns 3 since September 29 is in the third quarter of the year.
- `DatePart("ww", ToDateTime(1997, 9,14))` - Returns 38 since 1997-9-14 is in the 38th week of 1997.

Notes:

- The DatePart function with "yyyy" intervalType parameter is the same as the Year function. Similarly, the DatePart function with "m", "d", "w", "h", "n" and "s" intervalType argument is the same as the functions Month, Day, Weekday (or DayOfWeek), Hour, Minute and Second respectively. On the other hand, there is no easy alternative to using the DatePart function for the "q", "y" and "ww" intervalType parameters.
- The firstDayOfWeek parameter affects the DatePart function when the interval type parameter is "w" or "ww". For all other intervalType parameter values, it is ignored.
- The firstWeekOfYear parameter affects the DatePart function only when the intervalType argument is "ww". For all other intervalType argument values, it is ignored.