seconds(nSecs: Number): Period

Creates a Period value from the provided number of seconds.

Introduced in DataWeave version 2.4.0.


Name Description


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


This example shows how seconds behaves with different inputs. It adds and subtracts seconds from DateTime values. It also converts the decimal value 4.555 into the Period format (PT4.555S) and and the whole number 4 into the Period format (PT4S)


%dw 2.0
import * from dw::core::Periods
output application/json
  nextSecond: |2020-10-05T20:22:34.385Z| + seconds(1),
  previousSecond: |2020-10-05T20:22:34.385Z| - seconds(1),
  decimalInputPeriod: seconds(4.555),
  wholeNumberInputPeriod: seconds(4),
  addNegativeValue: seconds(-1) + seconds(2)


  "nextSecond": "2020-10-05T20:22:35.385Z",
  "previousSecond": "2020-10-05T20:22:33.385Z",
  "decimalInputPeriod": "PT4.555S",
  "wholeNumberInputPeriod": "PT4S",
  "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!