Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

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}]
share|improve this answer

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"} *)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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