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

# period

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

## period(period: { years?: Number, months?: Number, days?: Number }): Period

Creates a Period value as a date-based number of years, months, and days in the ISO-8601 calendar
system.

_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>{years:4, months:11, days:28}</code>. The key-value pairs are optional and can be specified in any order. An empty object (<code>{}</code>) returns the Period value <code>"P0D"</code> (zero days). The default value of each key is <code>0</code>. Valid values are whole numbers, which can be positive or negative. Decimal values produce an error message. Key names are selectable.</p></td></tr></tbody></table>

### Example

This example shows how `period` behaves with different inputs. The example add a subtracts and adds
the result of a `period` function to DateTime and Date values. It also constructs a Period value
from `period` objects and selects a `months` value from the object.

#### Source

```DataWeave
%dw 2.0
output application/json
import * from dw::core::Periods
---
{
   dayBeforeDateTime: |2020-10-05T20:22:34.385Z| - period({days:1}),
   dayAfterDate: |2020-10-05| + period({days:1}),
   yearMonthDayAfterDate: |2020-10-05| + period({years:1, months:1, days:1}),
   emptyPeriod: period({}),
   constructPeriod: period({years:4, months:11, days:28}),
   selectMonthsFromPeriod: period({years:4, months:11, days:28}).months
}
```

#### Output

```Json
{
    "dayBeforeDateTime": "2020-10-04T20:22:34.385Z",
    "dayAfterDate": "2020-10-06",
    "yearMonthDayAfterDate": "2021-11-06",
    "emptyPeriod": "P0D",
    "constructPeriod": "P4Y11M28D",
    "selectMonthsFromPeriod": 11
}
```
