Comparing Two Dates in Excel Returns FALSE

Last reviewed: November 30, 1994
Article ID: Q40159
The information in this article applies to:
  • Microsoft Excel for Windows, versions 2.x, 3.0, 4.0, 5.0
  • Microsoft Excel for OS/2, versions 2.2, 3.0
  • Microsoft Excel for the Macintosh, versions 2.2, 3.0, 4.0, 5.0

SUMMARY

You 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.

WORKAROUND

Use 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
KBSubcategory:

Additional words: 2.00 2.0 2.01 2.1 2.10 2.2 2.20 2.21 3.0 3.00
4.0 4.00 5.0 5.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 30, 1994
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.