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

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