unixtime_milliseconds_fromdatetime
This page explains how to use the unixtime_milliseconds_fromdatetime function in APL.
unixtime_milliseconds_fromdatetime converts a datetime value to a Unix timestamp that’s expressed in whole milliseconds since 1970-01-01 00:00:00 UTC.
Use the function when you need a timestamp as a number with an explicit unit. For example, to send epoch milliseconds to another system, to compare timestamps with numeric fields that store epoch milliseconds, or to aggregate a timestamp as a number with max(unixtime_milliseconds_fromdatetime(_time)).
unixtime_milliseconds_fromdatetime is the inverse of unixtime_milliseconds_todatetime.
Usage
Syntax
Parameters
| Name | Type | Description |
|---|---|---|
datetime | datetime | The datetime value to convert. Other types aren’t converted implicitly and return a compile error. |
Returns
A long value that represents the number of whole milliseconds since the Unix epoch. Precision finer than one millisecond is dropped, rounding down toward negative infinity, so datetime values before 1970 return negative numbers. If the input is null, the function returns null.
For example, print epoch_ms = unixtime_milliseconds_fromdatetime(datetime(2024-01-15T10:30:45.123456789Z)) returns 1705314645123.
Use case example
The HTTP access logs store the timestamp as a datetime and you want each event’s time as epoch milliseconds.
Query
Output
| _time | epoch_ms |
|---|---|
| 2026-12-02T07:37:03Z | 1,796,197,023,000 |
This query converts each event’s timestamp to whole milliseconds since the Unix epoch.
List of related functions
- unixtime_seconds_fromdatetime: Converts a
datetimevalue to a Unix timestamp in whole seconds. - unixtime_microseconds_fromdatetime: Converts a
datetimevalue to a Unix timestamp in whole microseconds. - unixtime_nanoseconds_fromdatetime: Converts a
datetimevalue to a Unix timestamp in whole nanoseconds. - unixtime_milliseconds_todatetime: Converts a Unix timestamp expressed in whole milliseconds to a
datetimevalue. This is the inverse ofunixtime_milliseconds_fromdatetime.