Datetime Part

datetime_part

Extracts a specified part from a datetime value.

Spec

datetime_part(part, datetime)
  • part: The part of the datetime to extract. Supported values include: "Year", "Quarter", "Month", "DayOfYear", "Day", "Hour", "Minute", "Second", "Millisecond", "Microsecond", "Nanosecond", "Week", "DayOfWeek"
  • datetime: The datetime value to extract the part from.

Return Value

The value of the specified part as an integer or string, depending on the part.

Example

Extract the year from a datetime:

datatable(dt: datetime)
[
    datetime(2024-06-01)
]
| extend year = datetime_part("Year", dt)
dtyear
2024-06-01T00:00:00Z2024

Extract the day of week (0=Sunday, 6=Saturday):

datatable(dt: datetime)
[
    datetime(2024-06-01)
]
| extend day_of_week = datetime_part("DayOfWeek", dt)
dtday_of_week
2024-06-01T00:00:00Z6