formatTimestamp - Writes out a timestamp as a formatted string
formatTimestamp
formats a timestamp
to a string with an optional format specification and destination 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.
Arguments
Name | Type | Required | Description |
---|---|---|---|
timestamp | timestamp | true | The timestamp to format |
format | string | false | The format to render the timestamp. Defaults to iso8601 |
tz | string | false | Must be a valid Time Zone string. See Time Zone section to find out more. |
Valid format values
The format
argument can be represented by a number of values. Some examples are:
'%Y-%m-%d'
- print the date only, e.g.'2023-04-05'
'%H:%M:%S'
- print the time only, e.g.'16:07:33'
'%F %H:%M:%S'
- print both date and time, e.g.'2023-04-05 16:07:33'
'iso8601'
- print a timestamp in ISO 8601 format, e.g.'2023-04-05T16:07:33.123Z'
'timestamp_milli'
- print a timestamp in milliseconds (13 digits), e.g.'1680710853123'
Example - print a timestamp with default format and +5h offset
choose formatTimestamp($m.timestamp, tz='+05') as ts # Result 1: { "ts": "2023-08-29T19:08:37.405937400+0500" }
Example - print only the year and month
choose formatTimestamp($m.timestamp, '%Y-%m') as ym # Result 2: { "ym": "2023-08" }
Example - print only the hours and minutes
Example - print a timestamp in milliseconds (13 digits)
choose formatTimestamp($m.timestamp, 'timestamp_milli') as ms # Result 4: { "ms": "1693318678696" }
Theme
Light