10
$\begingroup$

This isn't really causing me a problem at the moment, but it's weird. Is this documented anywhere?

When I ask for the difference in days and then in years between April 1, 2015 and October 1, 2015 the years comes out to be exactly .5, whereas I think it should be .50137.

If I use January 1 & July 3, which is the same number of days, I do get .50137.

DateDifference[{2015, 4, 1}, {2015, 10, 1}, "Day"]
%/Quantity[365. , "Days"/"Years"]
DateDifference[{2015, 4, 1}, {2015, 10, 1}, "Year"]

183 days
0.50137 years
0.5 years

DateDifference[{2015, 1, 1}, {2015, 7, 3}, "Day"]
%/Quantity[365. , "Days"/"Years"]
DateDifference[{2015, 1, 1}, {2015, 7, 3}, "Year"]

183 days
0.50137 years
0.50137 years
$\endgroup$
16
$\begingroup$

The reason for the result of

DateDifference[{2015, 4, 1}, {2015, 10, 1}, "Year"]

(* Quantity[0.5, "Years"] *)

is that 2016 is a leap year, so there are 366 days in the year between {2015, 4, 1} and {2016, 4, 1}. Therefore we get 183/366 or exactly 1/2 back.

Note also the documented DayCountConvention option,

DateDifference[{2015, 4, 1}, {2015, 10, 1}, "Year", DayCountConvention -> "Actual365"]

(* Quantity[0.50137, "Years"] *)

and the Wikipedia article on the same topic.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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