Σημείωση
Η πρόσβαση σε αυτή τη σελίδα απαιτεί εξουσιοδότηση. Μπορείτε να δοκιμάσετε να συνδεθείτε ή να αλλάξετε καταλόγους.
Η πρόσβαση σε αυτή τη σελίδα απαιτεί εξουσιοδότηση. Μπορείτε να δοκιμάσετε να αλλάξετε καταλόγους.
Returns date truncated to the unit specified by the format.
For the corresponding Databricks SQL function, see trunc function.
Syntax
from pyspark.databricks.sql import functions as dbf
dbf.trunc(date=<date>, format=<format>)
Parameters
| Parameter | Type | Description |
|---|---|---|
date |
pyspark.sql.Column or str |
input column of values to truncate. |
format |
literal string |
'year', 'yyyy', 'yy' to truncate by year, or 'month', 'mon', 'mm' to truncate by month Other options are: 'week', 'quarter' |
Returns
pyspark.sql.Column: truncated date.
Examples
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('1997-02-28',)], ['dt'])
df.select('*', dbf.trunc(df.dt, 'year')).show()
df.select('*', dbf.trunc('dt', 'mon')).show()