%dw 2.0
import * from dw::core::Periods
output application/json
---
{
nextMonth: |2020-10-05T20:22:34.385Z| + months(1),
fourMonthPeriod : months(4),
addNegativeValue: months(-1) + months(2)
}
months
months(nMonths: Number): Period
Creates a Period value from the provided number of months.
The function applies the period
function to the input value.
Introduced in DataWeave version 2.4.0.
Parameters
Name | Description |
---|---|
|
The number of months as a whole number. A positive or negative number is valid. |
Example
This example shows how months
behaves with different inputs.
It adds a month to a DateTime value, and it converts the
whole number 4
to a number of months in the Period format (P4M
).