형식으로 지정된 단위로 잘린 날짜를 반환합니다.
해당 Databricks SQL 함수에 대해 알아보려면 trunc 함수를 참조하세요.
문법
from pyspark.databricks.sql import functions as dbf
dbf.trunc(date=<date>, format=<format>)
매개 변수
| 매개 변수 | 유형 | Description |
|---|---|---|
date |
pyspark.sql.Column 또는 str |
자를 값의 입력 열입니다. |
format |
literal string |
'year', 'yyyy', 'yyy' to truncate by year, or 'month', 'mon', 'mm' to truncate by month other options are: 'week', 'quarter' |
Returns
pyspark.sql.Column: 잘린 날짜입니다.
예시
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()