# Different results with DateRange and LeapYearsQ in Mathematica 9 and 10

With Mathematica 9.0 for Mac OS X x86 (64-bit) (January 24, 2013) one could use

DateRange[{2000}, {2010}, "Year"]


to achive

{{2000}, {2001}, {2002}, {2003}, {2004}, {2005}, {2006}, {2007}, {2008}, {2009}, {2010}}


or

leapyears = Select[DateRange[{2000}, {2020}, "Year"], LeapYearQ[#] &]


with the result

{{2000}, {2004}, {2008}, {2012}, {2016}, {2020}}


With Mathematica 10.0 for Mac OS X x86 (64-bit) (June 29, 2014)

DateRange[{2000}, {2010}, "Year"]


one will get

{{2000, 1, 1}, {2001, 1, 1}, {2002, 1, 1}, {2003, 1, 1}, {2004, 1,
1}, {2005, 1, 1}, {2006, 1, 1}, {2007, 1, 1}, {2008, 1, 1}, {2009,
1, 1}, {2010, 1, 1}}


leapyears = Select[DateRange[{2000}, {2020}, "Year"], LeapYearQ[#] &]

{{2000, 1, 1}, {2004, 1, 1}, {2008, 1, 1}, {2012, 1, 1}, {2016, 1,
1}, {2020, 1, 1}}


The Function DateObject does not clear a bean to me

DateRange[DateObject[{2000}], DateObject[{2012}], "Year"]


So, how can i get rid of the additional month, day information on V10, i.e. using leapyears and DateObject returning Year only?

-

I would use:

DateRange[{2000}, {2010}, "Year"][[All, {1}]]

{{2000}, {2001}, {2002}, {2003}, {2004}, {2005}, {2006}, {2007}, {2008}, {2009}, {2010}}

% ~Select~ LeapYearQ

{{2000}, {2004}, {2008}}


Note the {1} in the Part parameters; see Head and everything except Head?

-
Thanks for the link & hint to use the marble in my head +1. – Louis Aug 22 '14 at 17:23

I'm afraid you now have to extract that information by yourself. This performs the same function as eldo's code, but instead of using Map twice I use Composition. It is also showcasing the new Mathematica 10 syntax.

Map[List@*First]@*Select[LeapYearQ]@DateRange[{2000}, {2020}, "Year"]


{{2000}, {2004}, {2008}, {2012}, {2016}, {2020}}

In order to extract the year from a DateObject you can use DateValue:

Map[List@*(DateValue[#, "Year"] &)]@Select[LeapYearQ]@DateRange[DateObject[{2000}], DateObject[{2012}], "Year"]


{{2000}, {2004}, {2008}, {2012}, {2016}, {2020}}

-
The first part of your answer is nothing but a V10 rephrasing of my earlier answer – eldo Aug 21 '14 at 20:54
@eldo No, it's faster. You iterate over the list twice because you use Map twice, but I use Composition so I only map over it once. You could do that in V9 as well. Anyway, I think the new V10 syntax should get some extra attention now in the beginning, and I was adding something else with my answer, it wasn't just consisting of that. – C. E. Aug 21 '14 at 20:55
Sorry, you're right, and the second part of your answer is +1 anyway. – eldo Aug 21 '14 at 20:57
@Pickett, Yep ... +1. – Louis Aug 22 '14 at 17:33

List /@ First /@ Select[DateRange[{2000}, {2020}, "Year"], LeapYearQ]

{{2000}, {2004}, {2008}, {2012}, {2016}, {2020}}