How to Validate a Character Date Field

Last reviewed: June 27, 1995
Article ID: Q128539
The information in this article applies to:
  • Microsoft FoxPro for Windows, versions 2.5x, 2.6, and 2.6a
  • Microsoft FoxPro for MS-DOS, versions 2.5x, 2.6, and 2.6a

SUMMARY

This article shows by example how to check the validity of a date that was entered into a character field instead of a date field.

MORE INFORMATION

The following function (DATEEVAL) shows how an entered character date can be verified to determine if it was entered in a valid date format that could be converted to an actual date by using the CTOD() function.

   FUNCTION DATEEVAL
   PARAMETERS Datevar
   IF ISDIGIT(DTOC(CTOD(Datevar)))
      RETURN .T.
   ELSE
      RETURN .F.
   ENDIF

This function respects the settings for SET DATE and SET CENTURY. It also assumes the default American (MM/DD/YY) format.

Here's how you would call the DATEEVAL function:

   Datevar="09/22/95"
   IF DATEEVAL(Datevar)
      WAIT WINDOW "This is a valid date!"
   ELSE
      WAIT WINDOW "This date is not in the proper format!"
   ENDIF


Additional reference words: FoxWin FoxDos 2.50 2.50a 2.50b 2.60 2.60a
KBCategory: kbprg kbcode
KBSubcategory: FxprgGeneral


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: June 27, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.