Search code examples
prestoamazon-athenatrino

Convert Current Timestamp UTC to CET


I'm trying to find a way to convert the current_timestamp into a different time zone.

The function current_timestamp in Simba Athena gives me the timestamp in UTC by default. I would like to get this same timestamp in the CET timezone. Please note that I would like to automate this conversion in my query.

I tried the convert_timezone('CET', current_timestamp) function, but it's not recognized in AWS Athena

In simpler works, I'm looking for a substitute for the SQL Server function GETUTCDATE() in Presto, except that i would like to get the CET timestamp. Any suggestions?


Solution

  • current_timestamp in Trino (formerly known as Presto SQL) returns a timestamp with time zone value in terms of the current session time zone. For instance, if the client is in America/Los_Angeles time zone:

    trino> select current_timestamp;
                        _col0
    ---------------------------------------------
     2020-08-26 09:14:43.259 America/Los_Angeles
    (1 row)
    

    You can check what's the current timezone for the session with current_timezone():

    trino> select current_timezone();
            _col0
    ---------------------
     America/Los_Angeles
    (1 row)
    

    To convert a timestamp with time zone to another time zone, you can use the AT TIME ZONE syntax:

    trino> select current_timestamp at time zone 'America/New_York';
                      _col0
    ------------------------------------------
     2020-08-26 12:18:37.901 America/New_York
    (1 row)