=?Utf-8?B?RmFtaWx5IFR yZWUgTWlrZQ==?=
<FamilyTreeMike @discussions.mi crosoft.comwrot e in news:8968EFD2-14D5- 4AD4-8939-F50FEC7D936E@mi crosoft.com:
I would use something akin to the following:
>
Sub Main()
Dim DOB As Date = New Date(1925, 8, 4) ' use your favorite
date
Dim Today As Date = Date.Now
>
Dim age As Integer = Today.Year - DOB.Year
>
If (Today.Month < DOB.Month) Then age = age - 1
If (Today.Month = DOB.Month) And (Today.Day < DOB.Day) Then _
age = age - 1
>
Console.WriteLi ne("Age: " & age)
>
Console.ReadLin e()
End Sub
>
>
Hope this helps...
>
On Mar 9, 4:00 pm, "Steve Gerrard" <mynameh...@com cast.netwrote:
Family Tree Mike wrote:
"Spam Catcher" wrote:
>
Can you just go Now.Subtract(DO B).Year?
>
That was my first thought, but my TimeSpan object doesn't have a Year
property. :(
>
Probably just as well, it wouldn't know how many years X number of days is
anyway. :(
>
If you want a one line version, and don't mind adding a boolean expression, you
could write
>
Dim age As Integer = Now.Year - DOB.Year + (New Date(Now.Year, DOB.Month,
DOB.Day) Now)
And this compiles with option strict on? It makes no sense to add a
boolean to an integer!
On Mar 9, 4:00 pm, "Steve Gerrard" <mynameh...@com cast.netwrote:
>If you want a one line version, and don't mind adding a boolean
>expression, you could write
>>
>Dim age As Integer = Now.Year - DOB.Year + (New Date(Now.Year,
>DOB.Month, DOB.Day) Now)
>
And this compiles with option strict on? It makes no sense to add a
boolean to an integer!
>
For option strict, you would need
Dim age As Integer = Now.Year - DOB.Year + CInt(New Date(Now.Year,
DOB.Month, DOB.Day) Now)
I didn't say I would go about adding booleans to integers, only that you could
if you wanted it all in one expression.;-)
Comment