Skip to content

Latest commit

 

History

History
58 lines (42 loc) · 1.05 KB

dw-periods-functions-months.adoc

File metadata and controls

58 lines (42 loc) · 1.05 KB

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

nMonths

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

Source

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

Output

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