'Extracting timestamp from timestamp with time zone Presto

Is there a native Presto function that provides support to extract the timestamp from a timestamp with time zone?

Taking something like this

SELECT 
PARSE_DATETIME('2022-03-13+02:00:99 UTC', 'yyyy-MM-dd+HH:mm:99 ZZZ') AT TIME ZONE 'UTC' AS utc_time

Which returns a value of:

2022-03-13+02:00:99 UTC

To:

2022-03-13+02:00:99

I couldn't find information in the docs for this kind of support. It seems as though my only option is to convert this as a varchar, remove the ' UTC' characters, and then re-convert this into a timestamp if I want to remove the time zone suffix from the timestamp with time zone



Solution 1:[1]

You can just cast to timestamp:

SELECT cast(PARSE_DATETIME('2022-03-13+02:00:99 UTC', 'yyyy-MM-dd+HH:mm:99 ZZZ') as timestamp) utc_time

Output:

utc_time
2022-03-13 02:00:00.000

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Guru Stron