programming-examples/python/Date/Display a list of the dates for the 2nd Saturday of every month for a given year.py
2019-11-15 12:59:38 +01:00

18 lines
614 B
Python

import calendar
# Show every month
for month in range(1, 13):
cal = calendar.monthcalendar(2020, month)
first_week = cal[0]
second_week = cal[1]
third_week = cal[2]
# If a Saturday presents in the first week, the second Saturday
# is in the second week. Otherwise, the second Saturday must
# be in the third week.
if first_week[calendar.THURSDAY]:
holi_day = second_week[calendar.THURSDAY]
else:
holi_day = third_week[calendar.THURSDAY]
print('%3s: %2s' % (calendar.month_abbr[month], holi_day))