Date Time Processing

Date Time Processing

Date/Time processing

The 'evaluation time’ - $now()

There are two functions that return the 'current' date/time timestamp:

1. [$now()](date-time-functions#now) returns the timestamp in an ISO 8601 formatted string.

2. [$millis()](date-time-functions#millis) returns the same timestamp as the number of milliseconds since midnight on 1st January 1970 UTC (the [Unix epoch](https://en.wikipedia.org/wiki/Unix_time)).

The timestamp is captured at the start of the expression evaluation, and that same timestamp value is returned for every occurrence of $now() and $millis() in the same expression for the duration of the evaluation.

Example

  • The timestamp will be the same for all invocations within an expression

<div class="jsonata-ex">

<div>{

"invoiceTime": $now(),

"total": $sum(Account.Order.Product.(Price * Quantity)),

"closingTime": $now()

}</div>

<div>{

"invoiceTime": "2018-12-10T13:49:51.141Z",

"total": 336.36,

"closingTime": "2018-12-10T13:49:51.141Z"

}</div>

</div>

JSON and ISO 8601

JSON does not have a built-in type for date/time values. The general [consensus](https://stackoverflow.com/a/15952652/7079134) is to store the date/time value as a string in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.

Example


{
    "myDateTime": "2018-12-10T13:45:00.000Z"
}

JSONata follows this convention and provides functions for formatting and parsing ISO 8601 formatted timestamps

([toMillis()](date-time-functions#tomillis) and [fromMillis()](date-time-functions#frommillis))

Support for other date/time formats

Since there is no standard for date/time format in JSON, it is entirely possible that the JSON data you are working with will have date/time values formatted in other ways. JSONata supports the highly versatile picture string notation from the XPath/XQuery [fn:format-dateTime()](https://www.w3.org/TR/xpath-functions-31/#func-format-dateTime) specification for both the formatting and parsing of a wide variety of date/time formats.

See [toMillis()](date-time-functions#tomillis) and [fromMillis()](date-time-functions#frommillis) for details.

Examples

  • The date 12/10/2018 in US format and 10/12/2018 in European format both refer to the same day.

<div class="jsonata-ex">

<div>$toMillis('10/12/2018', '[D]/[M]/[Y]') ~> $fromMillis('[M]/[D]/[Y]')</div>

<div>"12/10/2018"</div>

</div>

  • More verbose format.

<div class="jsonata-ex">

<div>$toMillis('10/12/2018', '[D]/[M]/[Y]')

~> $fromMillis('[FNn], [D1o] [MNn] [YI]')</div>

<div>"Monday, 10th December MMXVIII"</div>

</div>


    • Related Articles

    • Date Time Functions

      Date/Time functions Fuuz Context Where this applies in Fuuz: Date/time utilities are commonly used in Fuuz to timestamp transactions, align timezones across plants, and format values for downstream systems (e.g., SAP, Oracle, or machine HMIs). All ...
    • Screen Designer Element Types

      There are four categories of Element Types: Layout, Input, Display, and Interaction. In the properties tab on the right-hand side, you can see the element types organized by category. i.e. if you look under the category Layout the first element ...
    • Processing Model

      The JSONata processing model The JSONata type system JSONata is a superset of JSON and the JSONata type system is a superset of the JSON data types. In common with all functional programming languages, the function is also a first-class data type. ...
    • Screen Designer (UID)

      Executive Summary The Fuuz Screen Designer is a versatile and intuitive drag-and-drop tool that empowers users to design custom screens according to their specific requirements. With the Screen Designer, you can effortlessly create various types of ...
    • IBM DB2 SQL

      What is IBM DB2? IBM DB2 is a family of data management products, including database servers, developed by IBM. It is a powerful and versatile relational database management system (RDBMS) that is commonly used in enterprise environments to store, ...