0 points

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


dashboard

Tue Sep 01 2020 17:25:46 GMT+0000 (UTC)

Posted 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_copy Copy

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