M
Michael C#
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
(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