Contact Us 1-800-596-4880

hours

hours(nHours: Number): Period

Creates a Period value from the provided number of hours.

The function applies the duration function to the input value.

Introduced in DataWeave version 2.4.0.

Parameters

Name Description

nHours

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

Example

This example shows how hours behaves with different inputs. It adds and subtracts hours from DateTime and LocalTime values. It also converts the decimal value 4.555 into the Period format (PT4H33M18S) and the whole number 4 into the Period format (PT4H). Notice that hours(-1) + hours(2) returns the number of seconds.

Source

%dw 2.0
import * from dw::core::Periods
output application/json
---
{
   nextHour: |2020-10-05T20:22:34.385Z| + hours(1),
   previousHour: |2020-10-05T20:22:34.385Z| - hours(1),
   threeHoursLater: |20:22| + hours(3),
   addDecimalInput: |20:22| + hours(3.5),
   decimalInputAsPeriod : hours(4.555),
   fourHourPeriod : hours(4),
   addNegativeValue: hours(-1) + hours(2)
}

Output

{
   "nextHour": "2020-10-05T21:22:34.385Z",
   "previousHour": "2020-10-05T19:22:34.385Z",
   "threeHoursLater": "23:22:00",
   "addDecimalInput": "23:52:00",
   "decimalInputAsPeriod": "PT4H33M18S",
   "fourHourPeriod": "PT4H",
   "addNegativeValue": 3600
}