Article ID: 241728 - Last Review: June 28, 2004 - Revision: 3.0 PRB: Using 2-Digit Years with IsDate May Produce Unexpected Results
This article was previously published under Q241728 On This PageSYMPTOMS
The IsDate() function may return unexpected results if passed a date which contains a 2-digit year.
CAUSE
The VBA date functions IsDate, Format, CDate, and CVDate utilize a function found in OLE Automation (OleAut32.dll). This function searches all possible date formats by tokenizing each of the separated values in the string representing the date and returns a Boolean value indicating whether the input can be represented as a Date. This is important to remember when using the function to interpret a date that contains a 2 digit year. Different Locales use various date formats (that is, mm/dd/yy, yy/mm/dd, "DD MMM YY", "YY MMM DD", and so forth) and therefore the function tries the digits in all positions until the function has found a valid date or exhausted all possibilities. Checking whether February 29th is a valid date for a specific year, is one example of where you may get unexpected results when passing the IsDate function a date that contains a 2-digit year. To be more specific, passing the IsDate function an ambiguous date such as "29-FEB-01", will result in IsDate checking all available date formats and return TRUE because February 1, 2029 is a valid date. However, when the fully qualified year is passed in as "29-Feb-2001", then IsDate can determine that this is an invalid Date, and therefore will return FALSE. RESOLUTION
Create a wrapper function around the IsDate function to convert the date to a 4-digit year before passing the converted date to the IsDate() function.
STATUS
This behavior is by design.
MORE INFORMATION
The functions in OleAut32.dll use a standard "sliding year" so that, by default, all 2-digit years in the range 0 - 29 are considered to be in the 2000s and those in the range 30 - 99 are in the 1900s. This can be easily overridden with the following wrapper function. The documentation for the IsDate function defines it's designed behavior. IsDate(expression)
The required expression is a Variant containing a date expression or string expression recognizable as a date or time.
Steps to Reproduce Behavior
Steps to Avoid the Problem
APPLIES TO
| Other Resources Other Support Sites
CommunityGet Help NowArticle Translations |





















Back to the top