はじめに
Pythonで今日の日付を取得して色々加算・減算する方法です。
方法
from datetime import datetime
from dateutil.relativedelta import relativedelta
# 今日
today = datetime.today()
# 年月日をそれぞれ取り出す
year = today.year
month = today.month
day = today.day
# n日の加算・減算
today + relativedelta(days=3) # 3日後
today + relativedelta(days=-3) # 3日前
# n月の加算・減算
today + relativedelta(months=3) # 3ヶ月後
today + relativedelta(months=-3) # 3ヶ月前
# 当月末を取得
today + relativedelta(months=1, days=-1)