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