Skip to main content

$toMillis

$toMillis(timestamp?, picture?) -> number
Compact type signature<s-s?:n>

If timestamp is omitted, the current context value is used.

Source: JSONata

Documentation

Convert a timestamp string to the number of milliseconds since the Unix Epoch (1 January, 1970 UTC) as a number.

If the optional picture string is not specified, then the format of the timestamp is assumed to be ISO 8601. An error is thrown if the string is not in the correct format.

If the picture string is specified, then the format is assumed to be described by this picture string using the same syntax as the XPath/XQuery function fn:format-dateTime, defined in the XPath F&O 3.1 specification.

Examples

Basic usage

  • $toMillis("2017-11-07T15:07:54.972Z") => 1510067274972

Convert an encounter timestamp to epoch milliseconds

Input

This example uses the encounters example input in both JSON and CSV because the same expression works in either format. The expression reads the first encounter's start value and converts it to epoch milliseconds.

Example input

[
{
"encounterId": "enc-1001",
"patientId": "pat-0001",
"status": "finished",
"class": "outpatient",
"type": "primary-care",
"reason": "routine follow-up",
"facility": "ExampleCare Clinic",
"practitionerId": "prac-4001",
"start": "2026-02-14T09:30:00Z",
"end": "2026-02-14T10:05:00Z"
},
{
"encounterId": "enc-1002",
"patientId": "pat-0001",
"status": "finished",
"class": "outpatient",
"type": "imaging",
"reason": "headache evaluation",
"facility": "ExampleCare Imaging",
"practitionerId": "prac-4002",
"start": "2026-03-01T15:10:00Z",
"end": "2026-03-01T15:45:00Z"
},
{
"encounterId": "enc-1003",
"patientId": "pat-0001",
"status": "in-progress",
"class": "virtual",
"type": "care-coordination",
"reason": "medication questions",
"facility": "ExampleCare Clinic",
"practitionerId": "prac-4003",
"start": "2026-03-10T11:20:00Z",
"end": ""
},
{
"encounterId": "enc-1004",
"patientId": "pat-0001",
"status": "planned",
"class": "outpatient",
"type": "lab",
"reason": "fasting labs",
"facility": "ExampleCare Clinic",
"practitionerId": "prac-4001",
"start": "2026-03-20T08:00:00Z",
"end": ""
}
]

Expression

$toMillis($[0].start)

Result

1771061400000