Pythonの日付処理をまとめておく。(必要に応じて追記)
from datetime import datetime,timedelta
now = datetime.utcnow() + timedelta(hours=9)
▼昨日
last_day = now + timedelta(days=-1)
print(last_day.strftime("%Y-%m-%d"))
▼先月1日
last_month = datetime(now.year, now.month, 1) + timedelta(days=-1)
print(last_month.strftime("%Y-%m-01"))
▼昨年同月1日
last_year_same_month = datetime(now.year-1, now.month, 1)
print(last_year_same_month.strftime("%Y-%m-01"))