Comparing Two Dates in Excel Returns FALSELast reviewed: November 30, 1994Article ID: Q40159 |
The information in this article applies to:
SUMMARYYou must make sure that the serial numbers match exactly when comparing two dates in Microsoft Excel. If you enter the date 8/9/88, Excel will interpret this as the serial value 32364.0000000000, or 8/9/88 12:00:00. When the date becomes 8/9/88, the following function still returns FALSE, even though the date is now 8/9/88:
=IF(NOW()=DATEVALUE("8/9/88"),TRUE,FALSE)The function will return TRUE only when the date is 8/9/88 12:00:00.
WORKAROUNDUse the TRUNC function whenever comparing two dates in which the time is insignificant. The formula is as follows:
=IF(TRUNC(NOW())=DATEVALUE("8/9/88"),TRUE,FALSE)In Microsoft Excel 3.0, the TODAY() function may be used in place of TRUNC(NOW()). The TODAY function returns only the date portion of the serial value for the current date so the formula will evaluate correctly. The formula is as follows:
=IF(TODAY()=DATEVALUE("8/9/88"),TRUE,FALSE) |
KBCategory: kbusage
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |