Skip to content

fromUnixTime - Parse a timestamp from a unix timestamp

The fromUnixTime is helpful if you have a keypath that contains a unix timestamp, but it has not been parsed as a timestamp and is a number instead. The UNIX epoch starts on January 1, 1970 - earlier timestamps are represented by negative numbers.

Syntax

Like many functions in DataPrime, fromUnixTime supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.

fromUnixTime(unixTime: number, timeUnit: timeunit?): timestamp
unixTime: number.fromUnixTime(timeUnit: timeunit?): interval

Arguments

NameTypeRequiredDescription
unixTimenumbertrueThe unix timestamp to parse
timeUnittimeunitfalseThe units of the unix timestamp. Defaults to milli

Example - Basic usage

We can simply convert a numerical literal or keypath into a timestamp.

In this example, we interpret a numerical value as the number of miliseconds since epoch. This is then parsed into a field called ts.

choose fromUnixTime(1658958157515, 'ms') as ts # Result: { "ts": 1658958157515000000 }
choose 1658958157515.fromUnixTime('ms') as ts # Result: { "ts": 1658958157515000000 }