Incorrect Results Using Dates in Comparisons

ID: Q72017


The information in this article applies to:


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.

Additional query words: 2.00 2.0 2.01 2.1 2.10 2.2 2.21 2.20 3.0


Keywords          : 
Version           : 
Platform          : 
Issue type        : 

Last Reviewed: March 21, 1999