PRB: VarDateFromStr Does Not Consider Date Formats for Specific Locales

ID: Q241893


The information in this article applies to:
  • Microsoft Windows NT 4.0
  • Microsoft Windows 98
  • Microsoft Windows 95
  • Microsoft Win32 Software Development Kit (SDK)


SYMPTOMS

The VarDateFromStr function may return without an error when a seemingly invalid date is passed. Furthermore, the VarDateFromStr function may return without error, regardless of what the locale is set to.


CAUSE

In VarDateFromStr, the code does not strictly check the string passed against the date format of the default system locale, default user locale, or the locale passed to the function. The function returns without error if the passed string is valid in any of the following date formats:

  • DD-MM-YYYY


  • MM-DD-YYYY


  • YYYY-MM-DD



RESOLUTION

If you need to verify that the date is valid based on the specific date format for a locale, do not depend on the VarDateFromStr function. This implies that any code relying on the MFC function COleDateTime::ParseDateTime to do strict checking should be changed also because this MFC function uses VarDateFromStr internally. Microsoft recommends that you check the string first in your code before calling VarDateFromStr or COleDateTime::ParseDateTime to make sure it is a correct date for the date format of the locale.


STATUS

This behavior is by design.


MORE INFORMATION

When calling VarDateFromStr, even under the English (United States) locale, you can pass a date such as "29-2-01". This is evaluated to Jan 2, 2029, and VarDateFromStr will not return an error.

Additional query words: date parsing comparision conversion COleDateTime ParseDateTime

Keywords : kbNTOS400 kbWinOS95 kbWinOS98 kbDSupport kbGrpMFCATL
Version : WINDOWS:95; winnt:4.0
Platform : WINDOWS winnt
Issue type : kbprb


Last Reviewed: October 14, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.