Extracts a date part (such as the day, month, or year) from a date or timestamp string.
DatePart() function has two parameters:
dateString(string): Required. A string that contains a date or timestamp.
datePart(string): Required. The date part that you want to extract from the string. Accepted values:
You can specify a date string in several formats, including:
- ISO 8601 timestamp:
- ISO 8601 date:
- US date and time notation:
8/5/2023 1:41 PM
- Long-form notation:
5 August 2023or
August 5, 2023
- Date and time:
2023-08-05 1:41:23 PM
- Time only:
- Chinese and Japanese notation:
2023 年 8 月 5 日
- Korean notation:
2023년 8월 5일
The function doesn’t support these formats:
- Dates in which the day includes an ordinal suffix, such as
August 5th, 2023or
5th August 2023.
- Little-endian numeral notation, such as
5/8/2023to represent the 5th of August, 2023.
- Month names in languages other than English, such as
5 août 2023.
- Dates that include any numerals other than Western Arabic numerals, such as
- Dates based on any calendar system other than the Gregorian calendar, such as
18 Av, 5783or
18 Muharram, 1445.
This example extracts the year from a date string.
The example outputs the current year: