Skip to content

formatTimestamp

Description

Returns a timestamp formatted as a string, with optional control over the output format and time zone.

Syntax

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

formatTimestamp(timestamp: timestamp, format?: string, tz?: string): string
(timestamp: timestamp).formatTimestamp(format?: string, tz?: string): string

Arguments

NameTypeRequiredDescription
timestamptimestamptrueThe timestamp to format
formatstringfalseThe format specification. Defaults to iso8601
tzstringfalseA valid time zone string (see Time Zone section for details)

Example

Print a timestamp with a +5h offset using the default format**

choose formatTimestamp($m.timestamp, tz='+05') as ts
choose $m.timestamp.formatTimestamp(tz='+05') as ts

Output

{
"ts": "2023-08-29T19:08:37.405937400+0500"
}