convert_timezone function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime 13.3 LTS and above

Converts TIMESTAMP_NTZ to another time zone. The input column is converted to TIMESTAMP_NTZ type before the time zone conversion, if the input column is of TIMESTAMP or DATE or STRING type.

Syntax

convert_timezone([sourceTz, ]targetTz, sourceTs)

Arguments

  • sourceTz: An expression that returns a numeric or an interval value. If absent, the current session time zone is used as the source time zone.
  • targetTz: The time zone to which the input timestamp should be converted.
  • sourceTs: The TIMESTAMP_NTZ to convert.

Returns

A TIMESTAMP_NTZ.

Examples

> SELECT convert_timezone('America/Los_Angeles', 'UTC', timestamp_ntz'2021-12-06 00:00:00');
 2021-12-06 08:00:00

-- Current session local timezone: UTC
> SELECT convert_timezone('America/Los_Angeles', timestamp_ntz'2021-12-06 08:00:00');;
 2021-12-06 00:00:00