# Get first day of month (BOM), last day of month (EOM) for # a year (yyyy) and compute days of the month # Modified version of script from stackoverflow import datetime from datetime import date def get_eom_date(yr_yyyy): # Get End-of-Month (EOM) date # The day 28 exists in every month. 4 days later, it's always next month next_month = yr_yyyy.replace(day=28) + datetime.timedelta(days=4) # subtracting the number of the current day brings us back one month return next_month - datetime.timedelta(days=next_month.day) def days_between(date1, date2): return 1+(abs(date2 - date1).days) cy = 2020 yr_days = 0 for month in range(1, 13): bom_dt = datetime.date(cy, month, 1) eom_dt = get_eom_date(datetime.date(cy, month, 1)) yr_days += days_between(bom_dt, eom_dt) print(bom_dt, eom_dt,' ', days_between(bom_dt, eom_dt),' ', yr_days)
761