Skip to content

Instantly share code, notes, and snippets.

@carlynorama
Created May 31, 2018 03:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlynorama/4e62d369bc05fa57d448886fa51cf4dd to your computer and use it in GitHub Desktop.
Save carlynorama/4e62d369bc05fa57d448886fa51cf4dd to your computer and use it in GitHub Desktop.
Get the last Tuesday of the month
#https://rosettacode.org/wiki/Find_the_last_Sunday_of_each_month#Python
import sys
import calendar
year = 2018
if len(sys.argv) > 1:
try:
year = int(sys.argv[-1])
except ValueError:
pass
for month in range(1, 13):
last_tuesday = max(week[-6] for week in calendar.monthcalendar(year, month))
print('{}-{}-{:2}'.format(year, calendar.month_abbr[month], last_tuesday))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment