$toMillis
$toMillis(timestamp?, picture?) -> number<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
- JSON
- CSV
[
{
"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": ""
}
]
encounterId,patientId,status,class,type,reason,facility,practitionerId,start,end
enc-1001,pat-0001,finished,outpatient,primary-care,routine follow-up,ExampleCare Clinic,prac-4001,2026-02-14T09:30:00Z,2026-02-14T10:05:00Z
enc-1002,pat-0001,finished,outpatient,imaging,headache evaluation,ExampleCare Imaging,prac-4002,2026-03-01T15:10:00Z,2026-03-01T15:45:00Z
enc-1003,pat-0001,in-progress,virtual,care-coordination,medication questions,ExampleCare Clinic,prac-4003,2026-03-10T11:20:00Z,
enc-1004,pat-0001,planned,outpatient,lab,fasting labs,ExampleCare Clinic,prac-4001,2026-03-20T08:00:00Z,
Expression
$toMillis($[0].start)
Result
1771061400000