PRB: DateTime Subtraction May Not Produce an Exact Integer (258998)



The information in this article applies to:

  • Microsoft Visual FoxPro for Windows 5.0
  • Microsoft Visual FoxPro for Windows 5.0a
  • Microsoft Visual FoxPro for Windows 6.0

This article was previously published under Q258998

SYMPTOMS

When subtracting two DateTimes, the result is a floating point number. As such, the displayed value may not be the exact value. This may lead to further inaccuracies.

CAUSE

Floating point math is frequently inaccurate in any language.

RESOLUTION

When subtracting DateTimes, use ROUND(nDifference, 0) to ensure that you are working with the value you think you are.

MORE INFORMATION

Steps to Reproduce Behavior

To observe the problem, run the following code in the Command window:
lnDiff = {^2000-03-20 11:31:00} - {^2000-03-20 10:25:00}
? lnDiff                      && 3960
DISPLAY MEMORY LIKE lnDiff    && 3959.99996513
? INT(lnDiff)                 && 3960
? INT(lnDiff / 60)            && 65
? INT(ROUND(lnDiff, 0) / 60)  && 66

Modification Type:MajorLast Reviewed:4/11/2000
Keywords:kbDSupport kbprb kbXBase KB258998 kbAudDeveloper