duration(period: { days?: Number, hours?: Number, minutes?: Number, seconds?: Number }): Period

Creates a Period value that represents a number of days, hours, minutes, or seconds.

Introduced in DataWeave version 2.4.0.


Name Description


An object such as {days:4, hours:11, minutes:45, seconds: 55}. The key-value pairs are optional and can be specified in any order. An empty object ({}) returns the Period value "PT0S" (zero seconds). The default value of each key is 0. Valid values are whole or decimal numbers, which can be positive or negative. Key names are selectable.


This example shows how duration behaves with different inputs.


%dw 2.0
import * from dw::core::Periods
output application/json
   dayAfterDateTime: |2020-10-05T20:22:34.385Z| + duration({days: 1}),
   dayAndHourBeforeDateTime: |2020-10-05T20:22:34.385Z| - duration({days: 1, hours: 1}),
   pointInTimeBefore: |2020-10-05T20:22:34.385Z| - duration({days: 1, hours: 1, minutes: 20, seconds: 10}),
   emptyDuration: duration({}),
   constructDuration: duration({days:4, hours:11, minutes:28}),
   selectHoursFromDuration: duration({days:4, hours:11, minutes:28}).hours,
   decimalAsPeriod:  duration({seconds: 30.5}),
   addNegativeValue: duration({ minutes : 1 }) + duration({ seconds : -1 })


   "dayAfterDateTime": "2020-10-06T20:22:34.385Z",
   "dayAndHourBeforeDateTime": "2020-10-04T19:22:34.385Z",
   "pointInTimeBefore": "2020-10-04T19:02:24.385Z",
   "emptyDuration": "PT0S",
   "constructDuration": "PT107H28M",
   "selectHoursFromDuration": 11,
   "decimalAsPeriod": "PT30.5S",
   "addNegativeValue": 59

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!