pyspark.sql.functions.time_to_seconds#

pyspark.sql.functions.time_to_seconds(col)[source]#

Extracts seconds from TIME value (returns DECIMAL to preserve fractional seconds).

New in version 4.2.0.

Parameters
colColumn or column name

TIME value to convert.

Examples

>>> from pyspark.sql import functions as sf
>>> df = spark.sql("SELECT TIME'14:30:00.5' as time")
>>> df.select(sf.time_to_seconds('time')).show()
+---------------------+
|time_to_seconds(time)|
+---------------------+
|         52200.500000|
+---------------------+