The FROM_TZ function converts the input timestamp and time zone information into the time of the time zone where the current database resides.

To use the FROM_TZ function, you must install the polar_from_tz plug-in. Run the following command to install the plug-in:

CREATE EXTENSION polar_from_tz;

Syntax

from_tz(timestamp_value, time_zone_value)

Parameters

Parameter Description
timestamp_value The timestamp, such as 2020-11-26 08:00:00.
time_zone_value The time zone. The strings in the following formats are supported:
  • 'TZH:TZM' format, such as '+08:00'.
  • TZR format, such as America/Los_Angeles.
    Note You can execute the following statement to query the supported time zones:
    select * from pg_timezone_names;
  • TZD format, such as PST.
    Note You can execute the following statement to query the supported time zones:
    select * from pg_timezone_abbrevs;

Examples

  • If the value of time_zone_value is in the 'TZH:TZM' format, execute the following query statement:
    select from_tz('2020-11-26 08:00:00','+08:00') FROM dual;

    The following query result is returned:

    "2020-11-26 00:00:00+00"
  • If the value of time_zone_value is in the TZR format, execute the following query statement:
    select from_tz('2020-11-26 08:00:00','America/Los_Angeles') FROM dual;

    The following query result is returned:

    "2020-11-26 16:00:00+00"
  • If the value of time_zone_value is in the TZD format, execute the following query statement:
    select from_tz('2020-11-26 08:00:00','PST') FROM dual;

    The following query result is returned:

    "2020-11-26 16:00:00+00"