PRB: VarDateFromStr Does Not Consider Date Formats for Specific Locales (241893)



The information in this article applies to:

  • Microsoft Windows NT Server 4.0
  • Microsoft Windows NT Workstation 4.0
  • Microsoft Windows 98
  • Microsoft Windows 95
  • Microsoft Platform Software Development Kit (SDK) 1.0

This article was previously published under Q241893

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.

Modification Type:MinorLast Reviewed:7/11/2005
Keywords:kbprb KB241893