Microsoft Knowledge Base Email Alertz

The

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 241893 - Last Review: January 25, 2007 - Revision: 1.3

PRB: VarDateFromStr Does Not Consider Date Formats for Specific Locales

System TipThis article applies to a different version of Windows than the one you are using. Content in this article may not be relevant to you. Visit the Windows Vista Solution Center
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.

APPLIES TO
  • Microsoft Windows NT Server 4.0 Standard Edition
  • Microsoft Windows NT Workstation 4.0 Developer Edition
  • Microsoft Windows 98 Standard Edition
  • Microsoft Windows 95
  • Microsoft Platform Software Development Kit-January 2000 Edition
Keywords: 
kbprb KB241893
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

buki Report As Irrelevant  
Written: 10/18/2004 4:03 AM
After i coverted the Date String to COleDateTime using ParseDateTime, i used the COleDateTime::Format() method to convert the date back to String format. Compared the original string with this one and if it is not the same, it means, that the format of the given string is wrong...