Incorrect Results Using Dates in Comparisons

Last reviewed: November 3, 1994
Article ID: Q72017
The information in this article applies to:
  • Microsoft Excel for Windows, versions 2.x, 3.0, 4.0, 4.0a, 5.0
  • Microsoft Excel for OS/2, versions 2.2, 2.21, and 3.0

SUMMARY

When comparing dates, either the serial number for the date or the DateValue function must be used.

MORE INFORMATION

Example

A1: 2/15/91     B1: =IF(A1=2/15/91,TRUE,FALSE)

If you type the above entries into a worksheet, B1 will return FALSE.

Excel treats the date in the IF statement as a calculation and actually divides the numbers. For example, 2/15/91=.001465 is the result of dividing 2 by 15 and dividing the result by 91.

The DateValue function returns the serial number of a given date (in text form). Applying the DateValue function to the date in the IF statement will achieve the desired result:

   A1: 2/15/91     B1: =IF(A1=DATEVALUE("2/15/91"),TRUE,FALSE)

B1 now returns TRUE. The actual serial date can also be substituted for the DateValue function.

REFERENCES

"Microsoft Excel Function Reference." Version 3.00, pages 45, 125, 129.

"Microsoft Excel Functions and Macros." Version 2.1x, pages 41, 121.


KBCategory: kbusage
KBSubcategory:

Additional reference words: 2.00 2.0 2.01 2.1 2.10 2.2 2.21 2.20 3.00
3.0 4.00


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: November 3, 1994
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.