format_timestamp function

The format_timestamp function converts a timestamp into a string according to the specified pattern and the timezone.

Syntax:

STRING format_timestamp(<timestamp>,[pattern [, timezone])

Semantics:

Example 1 - For a passenger with a specific ticket number, print the estimated arrival time on the first leg according to the pattern and the timezone entered.

SELECT $info.estimatedArrival, format_timestamp($info.estimatedArrival, "MMM dd, yyyy HH:mm:ss O", "America/Vancouver") AS FormattedTimestamp
FROM BaggageInfo bag, bag.bagInfo.flightLegs[0] AS $info
WHERE ticketNo= 1762399766476

Explanation: In this query, you specify the estimatedArrival field, pattern, and full name of the timezone as arguments to the format_timestamp function to convert the timestamp string to the specified “MMM dd, yyyy HH:mm:ss” pattern.

Note: The letter ‘O’ in the pattern argument represents the ZoneOffset, which prints the amount of time that differs from Greenwich/UTC in the resulting string.

Output:

{"estimatedArrival":"2019-02-03T06:00:00Z","FormattedTimestamp":"Feb 02, 2019 22:00:00 GMT-8"}

Example 2 - Display the formatted timestamp.

SELECT format_timestamp('2024-05-08T09:41:00',"dd MMM, uuuu HH:mm:ss","Asia/Calcutta") AS TIMESTAMP1
FROM BaggageInfo
WHERE ticketNo=1762399766476

Explanation: In this query, you use the format_timestamp function to print the given timestamp in the specified pattern. During formatting, the function adjust the timestamp to the “Asia/Calcutta” timezone and displays the resulting timestamp in the “dd MMM, uuuu HH:mm:ss” pattern.

Output:

{"TIMESTAMP1":"08 May, 2024 15:11:00"}