calculateTimeDiff

The calculateTimeDiff task calculates the difference between two timestamps and returns the result as a duration.

Potential use case

Use this task to determine the remaining time (or elapsed time) between a recorded timestamp and today’s date.

Properties

Input variables

IncomingTypeDescriptionExample
firstTimeObjectRequired. The base time from which secondTime is subtracted. Must contain time (string representation of the time) and formatString (the moment.js format the time must adhere to).{ "formatString": "YYYY-MM-DDTHH:mm:ss.SSSSSSZZ", "time": "2023-06-21T15:02:07.254000-1100" }
secondTimeObjectRequired. The time subtracted from firstTime. Must contain the same time and formatString keys.{ "formatString": "YYYY-MM-DDTHH:mm:ss.SSSSSSZZ", "time": "2023-04-28T01:21:14.052000-1100" }

Output variables

OutgoingTypeDescription
timeDiffObjectThe difference between the two timestamps expressed as a duration in multiple units (milliseconds, seconds, minutes, hours, days, months, and years).

Example 1

In this example:

  • The firstTime property comes from the output of addDuration, another task in the workflow. The reference variable is newtime.
  • The secondTime property comes from the getTime task. The reference variable is time.
  • Because secondTime is less than firstTime, the outgoing timeDiff is a positive reference — for example, the number of days until a future date.
calculateTimeDiff task with firstTime from addDuration and secondTime from getTime

Example 2

In this example:

  • The firstTime property comes from the getTime task. The reference variable is time.
  • The secondTime property comes from addDuration. The reference variable is newTime.
  • Because secondTime is greater than firstTime, the outgoing timeDiff is a negative reference — for example, the elapsed time since the firstTime deadline was passed.
calculateTimeDiff task with firstTime from getTime and secondTime from addDuration, producing a negative timeDiff