---
schema_version: "1"
id: 8289477a95e345facef2c1d0341599a71aa35174c2d0f0029a1d28828477c915
title: hours
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.9/dw-periods-functions-hours.md
canonical_url: https://docs.mulesoft.com/dataweave/2.9/dw-periods-functions-hours
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 72b23c5f354810206d0bf10c09e3a5d78dca99282d77ecb90c6f6927dc048324
description: MuleSoft Documentation Site
release: "2.9"
latest: false
---
---
product: DataWeave
version: 2.9
---

# 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
}
```
