This tutorial will explain date_trunc function available in Pyspark which can be used to truncate some of fields of date/time/timestamp

PySpark: Dataframe Date Functions Part 3



➠ Truncate Year: yyyy or year can be passed as parameter to truncate year to return 1st day of the year.

➠ Truncate Month: month or MM can be passed as parameter to truncate month to return 1st day of the month.

➠ Truncate Day: Day or DD can be passed as parameter to truncate time to start from midnight(00:00:00).

➠ Truncate Quarter: quarter can be passed as parameter to truncate quarter to return 1st day of the quarter.

➠ Truncate Hour: hour can be passed as parameter to truncate minutes to start from zero.

➠ Truncate Minute: minute can be passed as parameter to truncate seconds to start from zero.

➠ Truncate Second: second can be passed as parameter to truncate milliseconds to start from zero.

➠ Truncate Week: week can be passed as parameter to return date of the beginning of the week.