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.


Name Description


A whole number for the number of years. A positive or negative number is valid.


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.


%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)


   "nextYear": "2021-10-05T20:22:34.385Z",
   "fourYearPeriod": "P4Y",
   "addNegativeValue": 12

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub
Submit your feedback!
Share your thoughts to help us build the best documentation experience for you!
Take our latest survey!