# How can I get the list of dates in the next $n$ years

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.

-

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}]

-

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"} *)
`
-