Facile à utiliser la méthode de remplacement.
from datetime import datetime
from dateutil.relativedelta import relativedelta
today = datetime.now().date()
print(today)
# => 2020-05-27
last_month_start = (today - relativedelta(months=1)).replace(day=1)
print(last_month_start)
# => 2020-04-01
last_month_end = today.replace(day=1) - relativedelta(days=1)
print(last_month_end)
# => 2020-04-30
Ne manquez pas le nom de la variable.
https://www.lifewithpython.com/2018/06/python-get-first-and-last-day-of-month.html
Recommended Posts