# YEAR

**The function YEAR takes a date or a DateTime and retrieves the four-digit year.**

This function takes either a single [DateTime](../../variable-data-types/the-datetime-variable-data-type) or a single [date](../../variable-data-types/the-date-variable-data-type) as input. It then returns the four-digit year described by the input.

#### Declaration

```javascript
YEAR(datetime) -> year
```

```javascript
YEAR(date) -> year
```

&#x20;

#### Parameters

**datetime** (type: _DateTime_) A DateTime to retrieve the year from.

**date** (type: _date_) A date to retrieve the year from.

#### Return Values

**year** (type: _number_) The 4-digit year described by the input.

#### Examples

Assume the first example has access to the following DateTime value:

```javascript
example_date_and_time = {  
 "date": {  
  "day": 1,  
  "month": 4,  
  "year": 2021  
 },  
 "time": {  
  "hour": 16,  
  "minute": 14,  
  "second": 38,  
  "millisecond": 0  
 },  
 "timeZone": "UTC"  
}
```

The following example retrieves the 4-digit year described in the DateTime **example\_date\_and\_time**. Note how the output matches the year given in the above variable.

```javascript
YEAR(example_date_and_time) = 2021
```

The above example demonstrates how the YEAR function behaves when given a DateTime as input. In order to further establish how the YEAR function behaves when given a date as input, assume the last example has access to the following date value:

```javascript
example_date = {  
 "day": 1,  
 "month": 4,  
 "year": 2021  
}
```

The following example retrieves the 4-digit year described in the DateTime **example\_date**. Note that the date described in **example\_date** is identical to the date described in **example\_date\_and\_time**, and YEAR returns the same value when given either as input:

```javascript
YEAR(example_date) = 2021
```
