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 or a DateTime, and a Number. It outputs the given Date or DateTime with the year value replaced by the given number.

Declaration

UPDATE_YEAR(datetime, new_year) -> new_datetime
UPDATE_YEAR(date, new_year) -> new_date

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:

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:

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:

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:

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

Last updated