---
schema_version: "1"
id: 2a69733724ea1652fba8bed4f9df7d766bdde0bd4b1615717bce4b5165068255
title: duration
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.4/dw-periods-functions-duration.md
canonical_url: https://docs.mulesoft.com/dataweave/2.4/dw-periods-functions-duration
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 5f1b0900c24cfd5760cc82497845542de536c029cfd569e289d837e218ef6c8a
description: MuleSoft Documentation Site
release: "2.4"
latest: false
---
---
product: DataWeave
version: 2.4
---

# duration

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

## duration(period: { days?: Number, hours?: Number, minutes?: Number, seconds?: Number }): Period

Creates a Period value that represents a number of days, hours, minutes, or seconds.

_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>period</code></p></td><td><p>An object such as <code>{days:4, hours:11, minutes:45, seconds: 55}</code>. The key-value pairs are optional and can be specified in any order. An empty object (<code>{}</code>) returns the Period value <code>"PT0S"</code> (zero seconds). The default value of each key is <code>0</code>. Valid values are whole or decimal numbers, which can be positive or negative. Key names are selectable.</p></td></tr></tbody></table>

### Example

This example shows how `duration` behaves with different inputs.

#### Source

```DataWeave
%dw 2.0
import * from dw::core::Periods
output application/json
---
{
   dayAfterDateTime: |2020-10-05T20:22:34.385Z| + duration({days: 1}),
   dayAndHourBeforeDateTime: |2020-10-05T20:22:34.385Z| - duration({days: 1, hours: 1}),
   pointInTimeBefore: |2020-10-05T20:22:34.385Z| - duration({days: 1, hours: 1, minutes: 20, seconds: 10}),
   emptyDuration: duration({}),
   constructDuration: duration({days:4, hours:11, minutes:28}),
   selectHoursFromDuration: duration({days:4, hours:11, minutes:28}).hours,
   decimalAsPeriod:  duration({seconds: 30.5}),
   addNegativeValue: duration({ minutes : 1 }) + duration({ seconds : -1 })
}
```

#### Output

```Json
{
   "dayAfterDateTime": "2020-10-06T20:22:34.385Z",
   "dayAndHourBeforeDateTime": "2020-10-04T19:22:34.385Z",
   "pointInTimeBefore": "2020-10-04T19:02:24.385Z",
   "emptyDuration": "PT0S",
   "constructDuration": "PT107H28M",
   "selectHoursFromDuration": 11,
   "decimalAsPeriod": "PT30.5S",
   "addNegativeValue": 59
}
```
