convert_timezone
Converts the timestamp without time zone sourceTs from the sourceTz time zone to targetTz.
For the corresponding Databricks SQL function, see convert_timezone function.
Syntax
Python
from pyspark.databricks.sql import functions as dbf
dbf.convert_timezone(sourceTz=<sourceTz>, targetTz=<targetTz>, sourceTs=<sourceTs>)
Parameters
Parameter | Type | Description |
|---|---|---|
|
| The time zone for the input timestamp. If it is missed, the current session time zone is used as the source time zone. |
|
| The time zone to which the input timestamp should be converted. |
|
| A timestamp without time zone. |
Returns
pyspark.sql.Column: A new column that contains a timestamp for converted time zone.
Examples
Python
spark.conf.set("spark.sql.session.timeZone", "America/Los_Angeles")
Python
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('2015-04-08 00:00:00',)], ['ts'])
df.select(
'*',
dbf.convert_timezone(None, dbf.lit('Asia/Hong_Kong'), 'ts')
).show()
df = spark.createDataFrame([('2015-04-08 15:00:00',)], ['ts'])
df.select(
'*',
dbf.convert_timezone(dbf.lit('Asia/Hong_Kong'), dbf.lit('America/Los_Angeles'), df.ts)
).show()
spark.conf.unset("spark.sql.session.timeZone")