以下 python 代码返回上个月的第一天/最后一天,但我希望能够返回 3 个月前的第一天
from datetime import date, timedelta
last_day_of_prev_month = date.today().replace(day=1) - timedelta(days=1)
start_day_of_prev_month = date.today().replace(day=1) - timedelta(days=last_day_of_prev_month.day)
print("First day of prev month:", start_day_of_prev_month)
print("Last day of prev month:", last_day_of_prev_month)
电流输出
#First day of prev month: 2021-04-01
#Last day of prev month: 2021-04-30