Tyler Whitaker's Infotech

Technology, Thoughts, & Opinions

Tyler Whitaker's Infotech header image 2

Date Palindromes

January 4th, 2010 · 1 Comment

So we hit a new decade just the other day, but what most of us missed was the significant of the next day, January 2nd, 2010. It was the first date palindrome for in this decade: 01/02/2010 or 01022010. Luckily Scott Lemon (@humancell) and Phil Windley (@windley) reminded me via twitter.

Which prompted me to write the following python code to figure out when the rest of these date palindromes occur within this millennium: (I know I could have used a list comprehension with filtering, but this wraps better…)

from datetime import datetime, timedelta
day = timedelta(hours=24)
def calc(start=None):
    date = datetime(2000, 1, 1)
    for i in range(0,365*1000):
        date = date + day
        str = date.strftime("%m%d%Y")
        if str == str[::-1]:
            print "%s %s" % (str, date.strftime("%m/%d/%Y"))

Which results in the following:
10022001 10/02/2001
01022010 01/02/2010
11022011 11/02/2011
02022020 02/02/2020
12022021 12/02/2021
03022030 03/02/2030
04022040 04/02/2040
05022050 05/02/2050
06022060 06/02/2060
07022070 07/02/2070
08022080 08/02/2080
09022090 09/02/2090
10122101 10/12/2101
01122110 01/12/2110
11122111 11/12/2111
02122120 02/12/2120
12122121 12/12/2121
03122130 03/12/2130
04122140 04/12/2140
05122150 05/12/2150
06122160 06/12/2160
07122170 07/12/2170
08122180 08/12/2180
09122190 09/12/2190
10222201 10/22/2201
01222210 01/22/2210
11222211 11/22/2211
02222220 02/22/2220
12222221 12/22/2221
03222230 03/22/2230
04222240 04/22/2240
05222250 05/22/2250
06222260 06/22/2260
07222270 07/22/2270
08222280 08/22/2280
09222290 09/22/2290

If you tweak the code to use the time format (“%m%d%y”) you get the 2 digit year palindromes which are really only interesting over a 100 year span since they repeat:

101101 10/11/01
102201 10/22/01
011110 01/11/10
012210 01/22/10
111111 11/11/11
112211 11/22/11
021120 02/11/20
022220 02/22/20
121121 12/11/21
122221 12/22/21
031130 03/11/30
032230 03/22/30
041140 04/11/40
042240 04/22/40
051150 05/11/50
052250 05/22/50
061160 06/11/60
062260 06/22/60
071170 07/11/70
072270 07/22/70
081180 08/11/80
082280 08/22/80
091190 09/11/90
092290 09/22/90

So get ready now for the 2 more this month, your next chance to party is in November of 2011.

Tags: General

1 response so far ↓

Leave a Comment