# Why DateDifference returns machine number?

Is there any specific reason why DateDifference cannot give an exact number in this case?

DateDifference["Jan 2, 2013", "Jan 8, 2013", "Week"]


0.857143

Also, I'd like to know how the various DayCountConvention settings interact with the calculation, in particular for "Week", "Month", etc.

-
That will return 1, yes. But why my example will not give 6/7? DateDifference will give a machine number in general in this case, when an exact number can be easily derived. – asterix314 Oct 29 '13 at 7:09

## 1 Answer

The reason might be gleaned from examining the output from TracePrint.

DateDifference["Jan 2, 2013", "Jan 8, 2013", "Week"] // TracePrint (* Warning Huge Output *)


Somewhere close to the end of this humongous output we see the following:

DataPacletsCalendarDataDumpn:Except[_Integer] :> N[DataPacletsCalendarDataDumpn]
6/7 /. DataPacletsCalendarDataDumpn:Except[_Integer] :> N[DataPacletsCalendarDataDumpn]


So it appears that Mathematica computes the difference using AbsoluteTime which gives an exact number and afterwards (if the result is not an Integer) takes the numerical value. Hence the result you get. To get around this one can do:

Rationalize[DateDifference["Jan 2, 2013", "Jan 8, 2013", "Week"]]


Which gives:

{6/7, "Week"}

-
This is missing the point. I want to know why, Mathematica being what it is, does not give me 6/7 in the first place. – asterix314 Oct 29 '13 at 7:24
+1 for tracing into the function and locating the N. But why use N when the result is not an integer? – asterix314 Oct 29 '13 at 13:46
@asterix314. That I cannot explain. There's no clue as to why in that huge TracePrint output either. – RunnyKine Oct 29 '13 at 17:41
@asterix314 I think as users we cannot really answer the "why" question in a satisfactory way. RunnyKine's response shows why the behavior arises, but if you don't like it or want someone to justify it to you, I think you'll have to raise it with support or file it as a bug. – Oleksandr R. Oct 29 '13 at 19:27