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.


Name Description


The number of months as a whole number. A positive or negative number is valid.


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


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


  "nextMonth": "2020-11-05T20:22:34.385Z",
  "fourMonthPeriod": "P4M",
  "addNegativeValue": 1

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!