This tutorial will explain various date/timestamp functions(Part 2) available in Pyspark which can be used to perform date/timestamp related operations.

PySpark: Dataframe Date Functions Part 2



last_day function(): last_day function can be used to get last date of the month for a date or timestamp.

next_day function(): next_day function can be used to get next date of the passed week day for a date or timestamp. This function takes a date or timestamp as 1st parameter and day of week ("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun") as 2nd parameter.

date_add function(): date_add function can be used to add or subtract days to a date or timestamp. This function takes a date or timestamp as 1st parameter and an integer (+ve to add months and -ve to subtact days) as 2nd parameter.

add_months function(): add_months function can be used to add or subtract months to a date or timestamp. This function takes a date or timestamp as 1st parameter and an integer (+ve to add months and -ve to subtact months) as 2nd parameter.

datediff function(): datediff function can be used to get number of days from start to end date or timestamp.

months_between function(): months_between function can be used to get number of months between start and end date or timestamp.