Last active
June 12, 2024 14:50
-
-
Save FernandoBontorin/ee3cb70a2c0473c28c278b9e170355b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pyspark.sql.functions import col, when, lit, last_day, add_months | |
| def retro_add_months(date, months): | |
| """ | |
| Adds 'months' to the given 'date', but if the resulting date is not the last day of the month, | |
| as well the given date, it returns the last day of the resulting month of added months. | |
| """ | |
| return when(last_day(date) != date, add_months(date, months)).otherwise(last_day(add_months(date, months))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment