At 04:41 PM 1/21/2003 +1300, Nigel Tidswell wrote:
I think I have hit a date calculation problem in MapInfo 7.0 on Win 2K.
... the code
below pasted into the MapBasic window will report 23,457 days between
the 2 dates.  A quick check in Excel will say 23,459 days.  Which should
I believe?

Example code:
...
basedate = "01-01-1900"
adate = "23-3-1964"
nodays = adate - basedate
...
Interesting observation!

First, let's get our facts straight.

(A) The correct answer is:

(1) From the start of 1/1/1900 to the start of 1/1/1964 there were 15 leap years, because 1900 itself was not a leap year and 1904, 1908, ..., 1960 were leap years.

(2) From the start of 1/1/1964 to the start of 3/23/1964 there were 31 + 29 + 22 days, because 1964 was a leap year.

The first accounts for 365 * 64 + 15 = 23,375 days. The second raises the total to 23,457 days.

(B) The answer Excel 2000 provides is 23,458 days, not 23,459. This is computed by subtracting one date from the other. So it is off by one day, not two.

Now, for the explanation: Excel mistakenly believes 1900 was a leap year. Incidentally, Excel also mistakenly believes 2100 will be a leap year.

Conclusion: Excel will find elapsed times correctly only for dates in the range 3/1/1900 .. 2/28/2100.

NB: The actual elapsed time between any two dates could legitimately be computed as one less than the value given by MapBasic or Excel (when it gets it right). It depends on how you interpret elapsed time. For instance, the amount of time between today and tomorrow could fairly be given as zero, because there is no gap between the two days. The calculations I used above compute elapsed times between the same clock times each day; in this sense, there is exactly one day between today and tomorrow.

--Bill Huber
Quantitative Decisions



---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 5052

Reply via email to