﻿---
title: ES|QL YEAR function
description: 
url: https://docs-v3-preview.elastic.dev/elastic/elasticsearch/tree/main/reference/query-languages/esql/functions-operators/date-time-functions/year
products:
  - Elasticsearch
---

# ES|QL YEAR function
<applies-to>
  - Elastic Cloud Serverless: Generally available
  - Elastic Stack: Planned
</applies-to>

Extracts the year from a date.

## Syntax

![Embedded](https://docs-v3-preview.elastic.dev/elastic/elasticsearch/tree/main/reference/query-languages/esql/images/generated/x-pack-esql/functions/year.svg)


## Parameters

<definitions>
  <definition term="date">
    Date expression. If `null`, the function returns `null`.
  </definition>
</definitions>


## Description

Extracts the calendar year from a date, using the [query time zone](/elastic/elasticsearch/tree/main/reference/query-languages/esql/directives/set#esql-time_zone). Equivalent to `DATE_EXTRACT("year", date)`. This function accepts a `date` or `date_nanos` value. Unix timestamps in seconds must be converted first. For example: `TO_DATETIME(start * 1000)`.

## Supported types


| date       | result |
|------------|--------|
| date       | long   |
| date_nanos | long   |


## Example

```esql
ROW dt = to_datetime("1996-03-21T00:00:00.000Z")
| EVAL year = YEAR(dt)
```