# UPDATE\_HOUR

**The function UPDATE\_HOUR changes the value of the hour in a Time or DateTime into another specified number.**

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

#### Declaration

```javascript
UPDATE_HOUR(datetime, new_hour) -> new_datetime
```

```javascript
UPDATE_HOUR(time, new_hour) -> new_time
```

&#x20;

#### Parameters

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

**time** (type: _Time_) Any time.

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

#### Return Values

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

**new\_time** (type: _Time_) The Time that results from taking the given Time and replacing the hour 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 time described in **example\_date\_and\_time** and replaces the given hour value (16) with 5. Note that the only difference between the output of this example and **example\_date\_and\_time** is the the value of the hour. When given a DateTime as input, UPDATE\_HOUR returns a DateTime:

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

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

```javascript
example_time = {  
 "hour": 16,  
 "minute": 14,  
 "second": 38,  
 "millisecond": 0  
}
```

The following example takes the time described in **example\_time** and replaces the given hour value (16) with 5. Note that the only difference between the output of this example and **example\_time** is the the value of the hour. When given a Time as input, UPDATE\_HOUR outputs a Time:

```javascript
UPDATE_HOUR(example_time, 2) = {  
 "hour": 5,  
 "minute": 14,  
 "second": 38,  
 "millisecond": 0  
}
```
