How do I convert to the proper Century in DateTime Format?
Posted on 2004-03-29
I am validating a text file as input in my VB.NET module. Trouble arises with six-digit date fields (ugh, the y2k beast is still around). I want to compare a Date of Birth field (from the 20th cent) with some other fairly current date value (from the 21st cent). But say I have a very old and distinguished person who has a DOB of 11/15/28 -- that's 11/15/1928. The below code coverts his DOB to 11/15/2028. I can't find any documentation that tells me how to convert a date value back to the last century based on a two-digit year.
My Culture is neutral (although this is an American web app).
Code looks like this:
Dim dfi As System.Globalization.DateTimeFormatInfo = New System.Globalization.DateTimeFormatInfo
dfi.ShortDatePattern = "MMddyy"
ElemValue = obts.Elem012 'DOB
ElemDateValue = DateTime.ParseExact(ElemValue, "d", dfi)
If ElemDateValue > TodaysDate Then
DoRuleViolation("Birth date > than Today is not allowed")