Microsoft KB Archive/241893

{|
 * width="100%"|

PRB: VarDateFromStr Does Not Consider Date Formats for Specific Locales

 * }

Q241893

-

The information in this article applies to:


 * Microsoft Windows NT Server version 4.0
 * Microsoft Windows NT Workstation version 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 : kbOSWinNT400 kbOSWin95 kbOSWin98 _IK kbGrpDSMFCATL

Issue type : kbprb

Technology : kbWinNTsearch kbWinNTWsearch kbWinNTW400 kbWinNTW400search kbWinNT400xsearch kbWinNTSsearch kbWinNTS400xsearch kbWinNTS400 kbWin32SDKSearch kbAudDeveloper kbWin95search kbWin98search kbSDKSearch kbZNotKeyword3 kbWin32sSearch kbWin98