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