Skip to content

toUnixTime - Represent a timestamp as time units since Epoch

toUnixTime converts a timestamp to a number of specific time units since the UNIX epoch (in UTC). The UNIX epoch starts on January 1, 1970.

NOTE: Timestamps from before Epoch are represented by negative numbers.

Syntax

toUnixTime(timestamp: timestamp, timeUnit: timeunit?): number

Arguments

Name Type Required Description
timestamp timestamp true The timestamp to be converted to a unix timestamp
timeUnit timeunit false The desired timeunit of the unix timestamp. Defaults to milli

Example - Changing the unix timestamp for compatability

Consider the following document:

{
    "ts": 1728769618374000000
}

Most systems expect the Unix timestamp to be in seconds. We can convert this using the toUnixTime function:

create ts_seconds from ts.toUnixTime('s')

This results in the following document:

{
    "ts": 1728769618374000000,
    "ts_seconds": 1728769618
}