FROM_TZ

FROM_TZ is a function in SQL that is used to convert a TIMESTAMP value and a specified TIME ZONE to a TIMESTAMP WITH TIME ZONE value.

FROM_TZ(TIMESTAMP, TIME_ZONE)

  • timestamp: The TIMESTAMP parameter is a value that indicates a specific point in time expressed in the Gregorian calendar with the precision of seconds, microseconds, or nanoseconds. It must include both date and time values and is expressed in a format that Oracle recognizes as a valid TIMESTAMP data type.
  • time_zone: The TIME_ZONE parameter is a textual string that represents the region or country that adheres to a specific yearly pattern for the adjustment of time, including changes related to daylight saving time. This string allows the conversion from local time to Coordinated Universal Time (UTC). The value should conform to the time zone region names as defined in the IANA Time Zone Database or be ‘UTC’.

Example

SELECT FROM_TZ(TIMESTAMP '1999-12-01 11:00:00', '4:00') AS New_Timestamp
FROM dual;

Output

NEW_TIMESTAMP
-------------------------------------------
01-DEC-99 11.00.00.000000000 AM AMERICA/NEW_YORK

Explanation

In the given example, the FROM_TZ function is used to produce a TIMESTAMP WITH TIME ZONE value. The initial timestamp ‘1999-12-01 11:00:00’ is combined with the time zone offset ‘+4:00’, resulting in the new TIMESTAMP WITH TIME ZONE value, which is represented in the ‘AMERICA/NEW_YORK’ time zone.

For in-depth explanations and examples SQL keywords where you write your SQL, install our extension.