获取当日的前一个月和后一个月
import datetime
from dateutil.relativedelta import relativedelta
print(datetime.date.today())
print(datetime.date.today() - relativedelta(months=+1))
print(datetime.date.today() - relativedelta(months=-3)
获取上一个月第一天和最后一天
from datetime import date
from dateutil.relativedelta import relativedelta
today = date.today()
d = today - relativedelta(months=1) #这个1指上一个月
date(d.year,d.month,1) #这里获取上一个月的
date(today.year,today.month,1) - relativedelta(days=1) #这里获取上个月最后一天