description |
---|
Convert timestamp to the specified timezone. |
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
{% code title="CONVERT_TIMEZONE example" %}
select convert_timezone('America/Los_Angeles', 'America/New_York', '2021-04-01 15:27:32')
-- 2021-04-01 18:27:32
{% endcode %}
{% code title="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
{% endcode %}
{% code title="CONVERT_TIMEZONE example" %}
select convert_timezone('PST', 'EST', '2021-04-01 15:27:32')
-- 2021-04-01 18:27:32
{% endcode %}
{% code title="CONVERT_TIMEZONE example" %}
select convert_timezone('America/Los_Angeles', 'America/New_York', '2021-04-01')
-- 2021-04-01 03:00:00
{% endcode %}
{% code title="CONVERT_TIMEZONE example" %}
select convert_timezone('America/Los_Angeles', 'America/New_York', date '2021-04-01')
-- 2021-04-01 03:00:00
{% endcode %}
{% code title="CONVERT_TIMEZONE example" %}
select convert_timezone('EDT', '2021-04-01 15:27:32')
-- 2021-04-01 11:27:32
{% endcode %}
{% code title="CONVERT_TIMEZONE example" %}
select convert_timezone('PST', '+02:00', '2021-04-01 15:27:32')
-- 2021-04-02 01:27:32
{% endcode %}
- The
sourceTimezone
anddestinationTimezone
parameters may betimezone_name
fromsys.timezone_names
,timezone_abbrev
fromsys.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.