Expressions

Date & Time

5min

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 . To cater to this scenario, add an onFocus with a set-state action to the .
component
onFocus


Be careful when using complex expressions, such as expressions that iterate one datasource across another, as your solution performance could become slower. To avoid this, try to use the datasource queries to get the desired result rather than an expression.



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