Skip to content

Instantly share code, notes, and snippets.

@samestep
Created September 10, 2019 00:26
Show Gist options
  • Save samestep/5bc3f2ef01d5d249b728954f16cd6837 to your computer and use it in GitHub Desktop.
Save samestep/5bc3f2ef01d5d249b728954f16cd6837 to your computer and use it in GitHub Desktop.
ISO 8601 palindrome dates with 4-digit years
import calendar
for year in range(10000):
year_string = '{:04d}'.format(year)
month_day = year_string[::-1]
month = int(month_day[0:2])
day = int(month_day[2:])
if 1 <= month <= 12:
weekday, days_in_month = calendar.monthrange(year, month)
if 1 <= day <= days_in_month:
print('{}{:02d}{:02d}'.format(year_string, month, day))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment