ACC: DateDiff() Function Returns Incorrect Value

Last reviewed: May 28, 1997
Article ID: Q104973
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0, 7.0

SYMPTOMS

Moderate: Requires basic macro, coding, and interoperability skills.

When you use the DateDiff() function on a large interval where the time periods are specified in minutes or seconds, the result is not correct.

CAUSE

The DateDiff() function returns a long integer. If the result is greater than the allowed range for long integers (-2,147,483,648 to 2,147,483,647), Microsoft Access truncates the value and returns the truncated value.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a new module. Enter the following in the module's Debug window (or Immediate window in versions 1.x and 2.0), and then press ENTER:

          ? DateDiff("n",#12-31-100#,#12-31-9999#)
    

    Note that the returned value, 911,403,103 minutes, is truncated because the actual value exceeds 2,147,483,647.

  2. Enter the following calculation, which is equivalent to the function above, and then press ENTER:

          x=#12-31-100#
          y=#12-31-9999#
          ? (y-x)*24*60
    

    Note that the returned value, 5,206,370,400 minutes, is correct. Note that Microsoft Access uses double-precision real numbers when doing immediate calculations.


Additional query words: date
Keywords : ExrOthr kbusage
Version : 1.0 1.1 2.0 7.0
Platform : WINDOWS
Hardware : X86
Issue type : kbprb
Resolution Type : Info_Provided


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: May 28, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.