addDuration

Unlike the getTime task (which provides a current system timestamp), the addDuration task adds a specified duration to an existing timestamp and returns the adjusted result for continued use in the automation.

Potential use case

If a date value is provided in a record, use addDuration to determine what the timestamp would be after adding additional time. For example, adding six months to a poll record could generate a result such as: “Last poll occurred on Jan 1; next poll will occur on Jun 1.”

Properties

Input variables

IncomingTypeDescriptionExample
inputTimeObjectRequired. A timestamp from a previous task. Must contain time (a string representation of the time) and formatString (the moment.js format the time must adhere to).{ "time": "2023-04-28T01:21:14.052000-1100", "formatString": "YYYY-MM-DDTHH:mm:ss.SSSSSSZZ" }
offsetDurationObjectRequired. A duration expressed as object literal notation (e.g., {"days": 7, "months": 1}) or as a plain numeric millisecond value.{"days": 7, "months": 1} / {"hours": 4} / 31556926000

When using object literal notation in offsetDuration, you must include the curly braces. Numeric values entered without any other designators are treated as milliseconds by default. See the moment.js documentation for more information.

Output variables

OutgoingTypeDescription
newTimeObjectThe new time after adding the given duration to inputTime. The format is inherited from inputTime.

The newTime object inherits the same format as inputTime. The addDuration task does not provide a mechanism to change the time format.

Example 1

In this example:

  • inputTime comes from the Get time task with reference variable time.
  • offsetDuration adds four days using object literal notation: {"days": 4}.
  • If inputTime is "2020-06-01", the resulting newTime is "2020-06-05".
addDuration task adding 4 days using object literal notation

Example 2

In this example:

  • inputTime comes from the Get time task with reference variable time.
  • offsetDuration is 86400000 milliseconds (24 hours), entered as a plain numeric value without object literal notation.
  • The resulting newTime is the inputTime plus 24 hours.
addDuration task adding 86400000 milliseconds as a plain numeric value

Example 3

In this example:

  • inputTime comes from the Get time task with reference variable time.
  • offsetDuration adds four hours and six months using object literal notation: {"hours": 4, "months": 6}.
  • The resulting newTime is the inputTime plus six months and four hours.
addDuration task adding 4 hours and 6 months using object literal notation

Manual reference variable entry (inputTime)

To enter the inputTime object manually, use Year-Month-Date-Time format ("yyyy-MM-dd'T'HH:mm:ss.SSSZ"):

1{"time": "2021-02-26T15:00:00.000Z"}

This displays as:

2021-02-25 03:00.00