CONVERT_TIMEZONE

Convert timestamp to the specified timezone.

Syntax

CONVERT_TIMEZONE(sourceTimezone string, destinationTimezone string, timestamp date, timestamp, or string in ISO 8601 format) → timestamp

  • sourceTimezone: The time zone of the timestamp. If you omit this parameter, Spice assumes that the source time zone is UTC.

  • destinationTimezone: The time zone to convert the timestamp to.

  • timestamp: The timestamp to convert.

Examples

CONVERT_TIMEZONE example
 SELECT CONVERT_TIMEZONE('America/Los_Angeles', 'America/New_York', '2021-04-01 15:27:32')
-- 2021-04-01 18:27:32
CONVERT_TIMEZONE example
SELECT CONVERT_TIMEZONE('America/Los_Angeles', 'America/New_York', TIMESTAMP '2021-04-01 15:27:32');
-- 2021-04-01 18:27:32
CONVERT_TIMEZONE example
SELECT CONVERT_TIMEZONE('PST', 'EST', '2021-04-01 15:27:32')
-- 2021-04-01 18:27:32
CONVERT_TIMEZONE example
SELECT CONVERT_TIMEZONE('America/Los_Angeles', 'America/New_York', '2021-04-01')
-- 2021-04-01 03:00:00
CONVERT_TIMEZONE example
SELECT CONVERT_TIMEZONE('America/Los_Angeles', 'America/New_York', DATE '2021-04-01')
-- 2021-04-01 03:00:00
CONVERT_TIMEZONE example
SELECT CONVERT_TIMEZONE('EDT', '2021-04-01 15:27:32')
-- 2021-04-01 11:27:32
CONVERT_TIMEZONE example
SELECT CONVERT_TIMEZONE('PST', '+02:00', '2021-04-01 15:27:32')
-- 2021-04-02 01:27:32

Usage Notes

  • The sourceTimezone and destinationTimezone parameters may be timezone_name from sys.timezone_names, timezone_abbrev from sys.timezone_abbrevs, or a UTC time offset such as “+02:00”.

  • If you specify a time zone name instead of time offset, you may get a different answer depending on when you call this function due to daylight saving time.

Last updated