python - How to get the last day of the month? - Stack Overflow

PHOTO EMBED

Tue Sep 01 2020 17:25:46 GMT+0000 (Coordinated Universal Time)

Saved by @arielvol #python

import datetime

def last_day_of_month(any_day):
    next_month = any_day.replace(day=28) + datetime.timedelta(days=4)  # this will never fail
    return next_month - datetime.timedelta(days=next_month.day)
content_copyCOPY

https://stackoverflow.com/questions/42950/how-to-get-the-last-day-of-the-month