How can I get the list of all dates from today 21.02.2012 (which is a palindrome) up to say next $n$ years? Then finding the other palindromes are not difficult. I could not find an easy way to generate the list using DateList.

link|improve this question

feedback

2 Answers

up vote 6 down vote accepted

Might I suggest a different approach?

Assuming that you are interested in dates in the format DD-MM-YYYY then:

Needs["Calendar`"]

Tuples @ Range @ {31, 12};

Append[#, FromDigits@StringReverse["" <> IntegerString[#, 10, 2]]] & /@ %;

palindromicDates = Select[%, DateQ[Reverse@#] &]

Gives all valid palindromic dates. You could filter out years below 1000 if you don't want those:

Cases[palindromicDates, {_, _, x_ /; x > 999}]
link|improve this answer
feedback

This is how you can get the dates:

n = 20;
dates = Table[DatePlus[Take[DateList[], 3], i], {i, 0, n 365}];

(I am approximating the year for 365 days for practical purposes---it's good enough here).

Then we can look for palindromes in different date formats:

Select[DateString[#, {"Day", "Month", "Year"}] & /@ dates, 
 StringReverse[#] == # &]

(* ==> {"21022012", "02022020", "12022021", "22022022", "03022030", "13022031"} *)

Select[DateString[#, {"Year", "Month", "Day"}] & /@ dates, 
 StringReverse[#] == # &]

(* ==> {"20200202", "20211202", "20300302"} *)
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.