date_trunc
Returns timestamp truncated to the unit specified by the format.
For the corresponding Databricks SQL function, see date_trunc function.
Syntax
Python
from pyspark.databricks.sql import functions as dbf
dbf.date_trunc(format=<format>, timestamp=<timestamp>)
Parameters
Parameter | Type | Description |
|---|---|---|
|
|
|
|
| input column of values to truncate. |
Returns
pyspark.sql.Column: truncated timestamp.
Examples
Python
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('1997-02-28 05:02:11',)], ['ts'])
df.select('*', dbf.date_trunc('year', df.ts)).show()
df.select('*', dbf.date_trunc('mon', 'ts')).show()