Orchestrator

Dynamic Date/Time Calculation

Content is machine translated from English by Phrase Language AI.

Workflows may require a date that is fetched at the runtime rather than hard-coded. This can be provided with sprig functions or Expr.

Sprig documentation references:

Expr documentation references:

Caution

Syntax used in the documentation at masterminds differs from what is used in Orchestrator. E.g., now | date "2006-01-02" becomes {{sprig.date("2006-01-02", sprig.now())}}

Use cases

Getting the current time/date

  • To just get the date at the time of the particular workflow execution, in any parameter field, enter:

    • Sprig: {{sprig.now()}}

    • Expr: {{ now() }}

  • At runtime, the date is returned in this format:

    "2023-02-24 11:33:01.819987888 +0000 UTC m=+77750.651866821"

Formatting a date

  • To format a date, use:

    • Sprig: sprig.date(“FORMAT_STRING”, “DATE”)

    • Expr: DATE.Format("FORMAT_STRING"

    Provide a string with the format required for the date referencing this standard date: Mon Jan 2 15:04:05 MST 2006  (MST is GMT-0700)

  • Examples:

    • Sprig: {{sprig.date("02.01.2006 - 15:04", sprig.now())}} results in “24.02.2023 - 11:36” (at time of writing).

    • Expr: {{ now().Format("02.01.2006 - 15:04") }}

    To provide the date in the format required by TMS API:

    • Sprig: ("2019-08-24T14:15:22Z") invoke {{sprig.date("2006-01-02T15:04:05Z", sprig.now())}}

    • Expr: {{ now().Format("2006-01-02T15:04:05Z") }}

Modifying a date

  • To perform a calculation based the example

    • Sprig: sprig.now(), use sprig.dateModify(“MODIFY_VALUE”, “DATE”).

    • Expr: DATE.Add(duration("MODIFY_VALUE"))

  • Example:

    • Sprig: {{sprig.dateModify("24h", sprig.now())}}

    • Expr: {{ now().Add(duration(“24h”)) }}

    (run on Feb 24th, 12:43) results in "2023-02-25 11:43:48.073101611 +0000 UTC m=+164796.904980545" - 24 hours after initial date.

  • Combinations can be used.

    To get the time and date of the execution, plus 24 hours, formatted for TMS API, pass this expression to the given field:

    • Sprig: {{sprig.date("2006-01-02T15:04:05Z", sprig.dateModify("24h", sprig.now()))}}

    • Expr: {{ now().Add(duration("24.h")).Format("2006-01-02T15:04:05Z") }}

    Resulting in "2023-02-25T11:50:50Z" (when run on Feb 24th, 11:50 hrs).

  • The value by which the date should be modified can be given in hours, with “-” if the value should be subtracted. Fractions such as “-1.5h” can also be used.

Was this article helpful?

Sorry about that! In what way was it not helpful?

The article didn’t address my problem.
I couldn’t understand the article.
The feature doesn’t do what I need.
Other reason.

Note that feedback is provided anonymously so we aren't able to reply to questions.
If you'd like to ask a question, submit a request to our Support team.
Thank you for your feedback.