unixtime_microseconds_fromdatetime
This page explains how to use the unixtime_microseconds_fromdatetime function in APL.
unixtime_microseconds_fromdatetime converts a datetime value to a Unix timestamp that’s expressed in whole microseconds 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 microseconds to another system, to compare timestamps with numeric fields that store epoch microseconds, or to aggregate a timestamp as a number with max(unixtime_microseconds_fromdatetime(_time)).
unixtime_microseconds_fromdatetime is the inverse of unixtime_microseconds_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 microseconds since the Unix epoch. Precision finer than one microsecond 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_us = unixtime_microseconds_fromdatetime(datetime(2024-01-15T10:30:45.123456789Z)) returns 1705314645123456.
Use case example
The HTTP access logs store the timestamp as a datetime and you want each event’s time as epoch microseconds.
Query
Output
| _time | epoch_us |
|---|---|
| 2026-12-02T07:37:03Z | 1,796,197,023,000,000 |
This query converts each event’s timestamp to whole microseconds since the Unix epoch.
List of related functions
- unixtime_seconds_fromdatetime: Converts a
datetimevalue to a Unix timestamp in whole seconds. - unixtime_milliseconds_fromdatetime: Converts a
datetimevalue to a Unix timestamp in whole milliseconds. - unixtime_nanoseconds_fromdatetime: Converts a
datetimevalue to a Unix timestamp in whole nanoseconds. - unixtime_microseconds_todatetime: Converts a Unix timestamp expressed in whole microseconds to a
datetimevalue. This is the inverse ofunixtime_microseconds_fromdatetime.