#!/usr/bin/env pythpn import datetime now = datetime.datetime.now() date_now = now.date() def get_date_month(mon=0): last_m = (int(now.year) * 12 + int(now.month) - mon) % 12 if len(str(last_m)) == 1: last_m = "%02d" % last_m last_y = int((
import datetime
now = datetime.datetime.now()
date_now = now.date()
def get_date_month(mon=0):
last_m = (int(now.year) * 12 + int(now.month) - mon) % 12
if len(str(last_m)) == 1:
last_m = "%02d" % last_m
last_y = int((int(now.year) * 12 + int(now.month) - mon) / 12)
last_mon = '%s%s' % (last_y, last_m)
return last_mon
last_mon = get_date_month(4);
print(last_mon)
$python get_year_month.py
202203