Poznámka
Na prístup k tejto stránke sa vyžaduje oprávnenie. Môžete sa skúsiť prihlásiť alebo zmeniť adresáre.
Na prístup k tejto stránke sa vyžaduje oprávnenie. Môžete skúsiť zmeniť adresáre.
Returns timestamp truncated to the unit specified by the format.
For the corresponding Databricks SQL function, see date_trunc function.
Syntax
from pyspark.sql import functions as dbf
dbf.date_trunc(format=<format>, timestamp=<timestamp>)
Parameters
| Parameter | Type | Description |
|---|---|---|
format |
literal string |
year, yyyy, yy to truncate by year, month, mon, mm to truncate by month, day, dd to truncate by day, Other options are: microsecond, millisecond, second, minute, hour, week, quarter |
timestamp |
pyspark.sql.Column or str |
input column of values to truncate. |
Returns
pyspark.sql.Column: truncated timestamp.
Examples
from pyspark.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()