DATEPART

Formulas / DATEPART
Return a part of a date.
DATEPART(interval, date, [firstdayofweek, firstweekofyear])
  • interval - required, string that indicates the interval of time to return
  • date - required, date to evaluate
  • firstdayofweek - [OPTIONAL] constant that indicates the first day of the week
  • firstdayofyear - [OPTIONAL] constant that indicates the first week of the year

Examples

  • DATEPART("yyyy", "11/14/2018")

    The date is the date to be used in the calculation and this example returns 2018.

  • The DATEPART function can be used with any of the valid interval values. These interval values are: Year ("yyyy" or "yy"), Quarter ("q"), Month ("m" or "mm"), Day of Year ("y"), Day ("d" or "dd"), Week ("ww"), Hour ("h"), Minute ("n"), and Second ("s").

  • DATEPART("w", "11/14/2018")

    The DATEPART function can be used to get the day of the week of a date. The "w" argument specifies that the day of the week is to be returned. The date is the date to be used in the calculation. This example returns 4, which is Wednesday.

Summary

The DATEPART function is a useful date/time function that can be used to extract a portion of a date/time value.

  • The DATEPART function can be used to extract the part of a date, such as year, month, or day.
  • The DATEPART function is a date/time function.


Frequently Asked Questions

What does the DATEPART function do?
The DATEPART function takes four arguments and returns a variant. It can be used to determine the date of a specific interval.
What are the arguments for the DATEPART function?
The arguments for the DATEPART function are interval, date, firstdayofweek, and firstdayofyear.
Are the firstdayofweek and firstdayofyear arguments optional?
Yes, both the firstdayofweek and firstdayofyear arguments are optional.
What does the firstdayofweek argument do?
The firstdayofweek argument determines the first day of the week.
Can the DATEPART function return the wrong week number?
Yes, the DATEPART function can return the wrong week number because the last Monday in some calendar years is not week 1 instead of week 53.
Sourcetable Logo

Work smarter

Al is here to help. Leverage the latest models to
analyze spreadsheets, enrich data, and create reports.

Drop CSV