Skip to main content

time_trunc

Returns time truncated to the unit.

Syntax

Python
from pyspark.databricks.sql import functions as dbf

dbf.time_trunc(unit=<unit>, time=<time>)

Parameters

Parameter

Type

Description

unit

pyspark.sql.Column or str

The unit to truncate the time to. Supported units are: "HOUR", "MINUTE", "SECOND", "MILLISECOND", and "MICROSECOND". The unit is case-insensitive.

time

pyspark.sql.Column or str

A time to truncate.

Returns

pyspark.sql.Column: A time truncated to the specified unit.

Examples

Python
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame(
[("HOUR", "13:08:15")],
['unit', 'time']).withColumn("time", dbf.col("time").cast("time"))
df.select('*', dbf.time_trunc('unit', 'time')).show()