Date & Time

Date and time expressions use the JSONata Date/Time functions to return various formats of date/time, date, or time. These expressions are used to get the current timestamp in ISO 8601 formatted string, use an expression over the timestamp to convert the timestamp into a specific format.

Configuration

Result
Expression

Current timestamp as ISO 8601

=$now()

Current datetime in milliseconds

=$toMillis($now())

Current date [M]/[D]/[Y]

=$fromMillis($toMillis($now()), '[M]/[D]/[Y]')

Current date [M01]/[D01]/[Y0001]

=$fromMillis($toMillis($now()), '[M01]/[D01]/[Y0001]')

Current datetime '[M01]/[D01]/[Y0001] [H01]:[m01]:[s01]'

=$fromMillis($toMillis($now()), '[M01]/[D01]/[Y0001] [H01]:[m01]:[s01]')

Current date [MI]/[DI]/[YI]

=$fromMillis($toMillis($now()), '[MI]/[DI]/[YI]')

Current date [D1o] [MNn] [Y]

=$fromMillis($toMillis($now()), '[D1o] [MNn] [Y]')

Current day

=$fromMillis($toMillis($now()), '[FNn]')

Current time

=$fromMillis($toMillis($now()), '[H01]:[m01]:[s01]')

Current time am/pm

=$fromMillis($toMillis($now()), '[h#1]:[m01][P]')

Current time '[H01]:[m01]:[s01] [z]', '-0500'

=$fromMillis($toMillis($now()), '[H01]:[m01]:[s01] [z]', '-0500')

Convert UTC to milliseconds

=$toMillis()

Convert millisecond to UTC

=$fromMillis()

Consideration

  • When using =$now() on a component level, the date/time is not refreshed when navigating out and into the jig. To cater to this scenario, add an onFocus with a set-state action to the jig.

children:
  - type: component.entity
    options:
      children:
        - type: component.entity-field
          options:
            label: Order Date
            value: [email protected]

Examples and code snippets

Date & time expressions
Date & time expressions

This example uses a component.enitity to show the results of various date/time functions

See the full code sample in GitHub.

expression.jigx
children:
  - type: component.entity
    options:
      children:
        - type: component.entity-field
          options:
            label: Current timestamp as ISO 8601
            value: =$now()
        - type: component.entity-field
          options:
            label: Current datetime in milliseconds
            value: =$toMillis($now())
        - type: component.entity-field
          options:
            label: Current date [M]/[D]/[Y]
            value: =$fromMillis($toMillis($now()), '[M]/[D]/[Y]')
        - type: component.entity-field
          options:
            label: Current date [M01]/[D01]/[Y0001]
            value: =$fromMillis($toMillis($now()), '[M01]/[D01]/[Y0001]')
        - type: component.entity-field
          options:
            label: Current datetime '[M01]/[D01]/[Y0001] [H01]:[m01]:[s01]'
            value: =$fromMillis($toMillis($now()), '[M01]/[D01]/[Y0001] [H01]:[m01]:[s01]')
        - type: component.entity-field
          options:
            label: Current date [MI]/[DI]/[YI]
            value: =$fromMillis($toMillis($now()), '[MI]/[DI]/[YI]')
        - type: component.entity-field
          options:
            label: Current date [D1o] [MNn] [Y]
            value: =$fromMillis($toMillis($now()), '[D1o] [MNn] [Y]')
        - type: component.entity-field
          options:
            label: Current day
            value: =$fromMillis($toMillis($now()), '[FNn]')
        - type: component.entity-field
          options:
            label: Current time
            value: =$fromMillis($toMillis($now()), '[H01]:[m01]:[s01]')
        - type: component.entity-field
          options:
            label: Current time am/pm
            value: =$fromMillis($toMillis($now()), '[h#1]:[m01][P]')
        - type: component.entity-field
          options:
            label: Current time '[H01]:[m01]:[s01] [z]', '-0500'
            value: =$fromMillis($toMillis($now()), '[H01]:[m01]:[s01] [z]', '-0500')

Last updated

Was this helpful?