# UPDATE\_YEAR

**The function UPDATE\_YEAR changes the year described by a Date or DateTime into another specified number.**

This function takes two pieces of input: a [Date](../../variable-data-types/the-date-variable-data-type) or a [DateTime](../../variable-data-types/the-datetime-variable-data-type), and a Number. It outputs the given Date or DateTime with the year value replaced by the given number.

#### Declaration

```javascript
UPDATE_YEAR(datetime, new_year) -> new_datetime
```

```javascript
UPDATE_YEAR(date, new_year) -> new_date
```

&#x20;

#### Parameters

**datetime** (type: _DateTime_) Any DateTime.

**date** (type: _Date_) Any date.

**new\_year** (required, type: _Number_) The new year; this is the number that will replace whatever value is currently associated with the year in the given Date or DateTime.

#### Return Values

**new\_datetime** (type: _DateTime_) The DateTime that results from taking the given DateTime and replacing the year value with the given number.

**new\_date** (type: _Date_) The Date that results from taking the given Date and replacing the year value with the given number.

#### 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 takes the date described in **example\_date\_and\_time** and replaces the given year value (2021) with 2022. Note that the only difference between the output of this example and **example\_date\_and\_time** is the the value of the year. When given a DateTime as input, UPDATE\_YEAR returns a DateTime:

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

The above example demonstrates how the UPDATE\_YEAR function behaves when given a DateTime as input. In order to further establish how the UPDATE\_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 takes the Date described in **example\_date** and replaces the given year value (2021) with 2022. Note that the only difference between the output of this example and **example\_date** is the the value of the year. When given a Date as input, UPDATE\_YEAR outputs a Date:

```javascript
UPDATE_YEAR(example_date, 2022) = {  
 "day": 1,  
 "month": 4,  
 "year": 2022  
}
```
