# DATE_EXTRACT

The DATE_EXTRACT function retrieves specific components from a date, such as the year, month, day, or hour.

## Syntax

`DATE_EXTRACT(datePart, date)`

### Parameters

#### datePart

Specifies which part of the date to extract. Possible values include: `aligned_day_of_week_in_month`, `aligned_day_of_week_in_year`, `aligned_week_of_month`, `aligned_week_of_year`, `ampm_of_day`, `clock_hour_of_ampm`, `clock_hour_of_day`, `day_of_month`, `day_of_week`, `day_of_year`, `epoch_day`, `era`, `hour_of_ampm`, `hour_of_day`, `instant_seconds`, `micro_of_day`, `micro_of_second`, `milli_of_day`, `milli_of_second`, `minute_of_day`, `minute_of_hour`, `month_of_year`, `nano_of_day`, `nano_of_second`, `offset_seconds`, `proleptic_month`, `second_of_day`, `second_of_minute`, `year`, or `year_of_era`. If set to `null`, the function returns `null`.

#### date

The date expression from which to extract the specified part. If set to `null`, the function returns `null`.

## Examples

Extracts the year component from a date parsed from the string "2022-05-06".
```esql
ROW date = DATE_PARSE("yyyy-MM-dd", "2022-05-06")
| EVAL year = DATE_EXTRACT("year", date)
```

Finds all events in the `sample_data` index that occurred before 9 AM or after 5 PM based on the `@timestamp` field.
```esql
FROM sample_data
| WHERE DATE_EXTRACT("hour_of_day", @timestamp) < 9
    AND DATE_EXTRACT("hour_of_day", @timestamp) >= 17
```