---
schema_version: "1"
id: a845d6e01572f8e9bf33454150d4f6eaafe0d253796165b822e7f7e9518276de
title: hours
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/latest/dw-periods-functions-hours.md
canonical_url: https://docs.mulesoft.com/dataweave/latest/dw-periods-functions-hours
source_site: docs.mulesoft.com
content_type: documentation
content_hash: dc7ec16f35af94e63a283125981fe86d11f133c5d4c206d7aeaa549b0e46360f
description: MuleSoft Documentation Site
release: "2.13"
latest: true
---
---
product: DataWeave
version: 2.13
is-latest-version: true
---

# hours

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## hours(nHours: Number): Period

Creates a Period value from the provided number of hours.

The function applies the `duration` function to the input value.

_Introduced in DataWeave version 2.4.0._

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>nHours</code></p></td><td><p>The number of hours as a whole or decimal number. A positive or negative number is valid.</p></td></tr></tbody></table>

### Example

This example shows how `hours` behaves with different inputs. It adds and subtracts hours from
DateTime and LocalTime values. It also converts the decimal value `4.555` into the Period format
(`PT4H33M18S`) and the whole number `4` into the Period format (`PT4H`). Notice that
`hours(-1) + hours(2)` returns the number of seconds.

#### Source

```DataWeave
%dw 2.0
import * from dw::core::Periods
output application/json
---
{
   nextHour: |2020-10-05T20:22:34.385Z| + hours(1),
   previousHour: |2020-10-05T20:22:34.385Z| - hours(1),
   threeHoursLater: |20:22| + hours(3),
   addDecimalInput: |20:22| + hours(3.5),
   decimalInputAsPeriod : hours(4.555),
   fourHourPeriod : hours(4),
   addNegativeValue: hours(-1) + hours(2)
}
```

#### Output

```Json
{
   "nextHour": "2020-10-05T21:22:34.385Z",
   "previousHour": "2020-10-05T19:22:34.385Z",
   "threeHoursLater": "23:22:00",
   "addDecimalInput": "23:52:00",
   "decimalInputAsPeriod": "PT4H33M18S",
   "fourHourPeriod": "PT4H",
   "addNegativeValue": 3600
}
```
