Skip to content

Instantly share code, notes, and snippets.

@sharuzzaman
Created January 13, 2020 08:40
Show Gist options
  • Save sharuzzaman/9f20627d6c291c1fdf36e792c0e7c0e5 to your computer and use it in GitHub Desktop.
Save sharuzzaman/9f20627d6c291c1fdf36e792c0e7c0e5 to your computer and use it in GitHub Desktop.
last sunday of the month for the year
#!/bin/env python3
import calendar
import datetime
now = datetime.datetime.now()
cal = calendar.Calendar()
month = 1
while month <= 12:
sundays_in_month = [x for x in cal.itermonthdays2(now.year,month) if x[0] != 0 and x[1] == 6]
last_sunday = sundays_in_month[-1]
print(last_sunday[0], calendar.month_name[month], now.year)
month = month + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment