Skip to content

Convert a timestamp

Problem / Use case

You have a Unix timestamp (or timestamp string) and want to display it in a human-readable format for logs, alerts, or dashboards.

There are several ways that this conversion can be performed. You can choose the one that best fits your use case.

formatTimestamp

formatTimestamp gives the user the flexibility to specify the output format. The first parameter is the timestamp and the second is the format. You ca use iso8601 without having to manually specify that format.

// date only
>>> formatTimestamp(1745905982439, '%Y-%m-%d')
'2025-04-29'

// time only
>>> formatTimestamp(1745905982439, '%H:%M:%S')
'05:53:02'

// date and time
>>> formatTimestamp(1745905982439, '%F %H:%M:%S')
'2025-04-29 05:53:02'

// iso8601 format (same as toIso8601DateTime)
>>> formatTimestamp(1745905982439, 'iso8601')
'2025-04-29T05:53:02.439Z'

toIso8601DateTime (DEPRECATED)

This shouldn’t be used, but you might see toIso8601DateTime in older queries. This function will accepts a timestamp as an argument and returns the corresponding ISO 8601 formatted time string.

>>> toIso8601DateTime(1745905982439)
'2025-04-29T05:53:02.439Z'

Since it’s deprecated use formatTimestamp(<timestamp>, 'iso8601') instead.

TL;DR

Use formatTimestamp with a parsed or converted timestamp for clean, flexible datetime formatting. Avoid toIso8601DateTime().