Incorrect Results Using Dates in ComparisonsLast reviewed: November 3, 1994Article ID: Q72017 |
The information in this article applies to:
SUMMARYWhen 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
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |