หมายเหตุ
การเข้าถึงหน้านี้ต้องได้รับการอนุญาต คุณสามารถลอง ลงชื่อเข้าใช้หรือเปลี่ยนไดเรกทอรีได้
การเข้าถึงหน้านี้ต้องได้รับการอนุญาต คุณสามารถลองเปลี่ยนไดเรกทอรีได้
Returns timestamp truncated to the unit specified by the format.
For the corresponding Databricks SQL function, see date_trunc function.
Syntax
from pyspark.databricks.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.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()