Michael,
I normally define a variable (possible a readonly class field) that is the
"minor" date, then compare my date of birth to it.
Something like:
Dim minorDob As DateTime = DateTime.Today.AddYears(-18)
Debug.WriteLine(minorDob, "minor date")
For Each dob As DateTime In New DateTime() {#3/18/1987#,
#3/19/1987#, #3/20/1987#, #3/21/1987#, #3/22/1987#}
If minorDob.CompareTo(dob) < 0 Then
Debug.WriteLine(dob, "minor")
Else
Debug.WriteLine(dob, "adult")
End If
Next
Hope this helps
Jay
"Michael C#" <xy*@abcdef.com> wrote in message
news:07******************@fe10.lga...
Given a DateTime variable, what's the best way to check "minor" status
(i.e., less than age 18 years) based on today's date? I came up with
this:
Dim minor As Boolean = true
'dtDOB is a DateTime variable set to Date of Birth
If (DateTime.Now.Subtract(dteDOB.Value.AddYears(18)). TotalDays >= 0) Then
minor = false
End If
This appears to work, but seems a little obfuscated. I was just wondering
if there was an easier way, and also to double-check my sanity and make
sure that my logic/implementation aren't screwy.
Thanks