Those of us who lived through Y2K remember that, after all was said and done, it was little more than an inconvenience. Fix a couple of reports displaying “19100” here and correct some validation logic there. Although Sherman wasn’t there to experience all of the Y2K fun, as a maintenance programmer, he has had the pleasure of experiencing exactly what it was like, each and every year.

In fact, his very first assignment was to fix a Y2.007K bug in an application developed the previous year: the original developer simply hard-coded 2006 as the year. And it wasn’t the only Y2.007 bug.

2008 introduced a whole slew of problems, but most of the problems had an easy work-around: just wait until March 1st. It’s not that the developers didn’t know about the leap year, it’s just they had very often implemented the logic incorrectly.

Last year (2010) was a bigger than he figured, one, as several developers (many just copy/pasting from each other) believed you could simply take the last digit of the year and increment it to find the next year... leaving the current year as 2000 or 20011.

And sadly, this year was no different. One of the very first tickets of 2011 was a high-priority, fix-by-January-2nd issue that centered around the following code.

```Function CheckValidDate(thisDate As String)
CheckValidDate = True
Dim thisChar As String
Dim i As Integer

Dim slashCount As Integer
Dim dayStr As String
Dim monthStr As String
Dim yearStr As String

Dim myAsc As Long

For i = 0 To Len(thisDate) - 1
thisChar = Left(thisDate, i + 1)
thisChar = Right(thisChar, 1)

myAsc = Asc(thisChar)

If (thisChar = "/") Then
slashCount = slashCount + 1
ElseIf (slashCount = 0) Then
monthStr = monthStr & thisChar
ElseIf (slashCount = 1) Then
dayStr = dayStr & thisChar
Else
yearStr = yearStr & thisChar
End If

If ((myAsc < 47 Or myAsc > 57) And myAsc <> Asc("/")) Then
CheckValidDate = False
End If
Next

If (slashCount <> 2) Then
CheckValidDate = False
End If

If (CheckValidDate = True) Then
Dim dayInt As Integer
Dim monthInt As Integer
Dim yearInt As Integer
dayInt = CInt(dayStr)
monthInt = CInt(monthStr)
yearInt = CInt(yearStr)

If (monthInt < 1 Or monthInt > 12) Then
CheckValidDate = False

ElseIf (monthInt = 2) Then
If (dayInt > 28 And yearInt Mod 4 <> 0) Then
CheckValidDate = False
ElseIf (dayInt > 29 And yearInt Mod 4 = 0) Then
CheckValidDate = False
End If

ElseIf ((monthInt = 4 Or monthInt = 6 Or monthInt = 9 Or monthInt = 11) And dayInt > 30) Then
CheckValidDate = False

ElseIf (dayInt > 31) Then
CheckValidDate = False
End If

If ((yearInt > 10 And yearInt < 100) Or (yearInt > 100 And yearInt < 2000) Or (yearInt > 2010)) Then
CheckValidDate = False
End If

End If

End Function```

Sherman replaced the entire method body with `CheckValidDate = IsDate(thisDate)`.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!