W
Woody Splawn
I am trying to determine the age of a person based on two dates, the Date of
Birth and Today().
I have a function that does this but it is kludgey and is giving me an age
that is pretty close but only because I have figured into the equation
(manually) the approximate number of leap years.
The code reads:
Dim TS As New TimeSpan
Dim NumDays As Integer
Dim age As Double
Dim DaysInYear As Integer = 365
Dim LeapYearDays As Integer = 10
StartDate = #11/5/1946#
EndDate = #10/29/2003#
TS = EndDate.Subtract(StartDate)
NumDays = CInt(TS.TotalDays.ToString)
NumDays = NumDays - LeapYearDays
age = (NumDays / DaysInYear)
MsgBox("Number days: " + NumDays.ToString)
MsgBox("Age: " + age.ToString)
I would guess there is a better cleaner way of getting what I want. How do
I factor-in leap years without using a hard coded value like 10? In this
case I just sort guesstimated that there were two leap years for each 10
years of age.
Birth and Today().
I have a function that does this but it is kludgey and is giving me an age
that is pretty close but only because I have figured into the equation
(manually) the approximate number of leap years.
The code reads:
Dim TS As New TimeSpan
Dim NumDays As Integer
Dim age As Double
Dim DaysInYear As Integer = 365
Dim LeapYearDays As Integer = 10
StartDate = #11/5/1946#
EndDate = #10/29/2003#
TS = EndDate.Subtract(StartDate)
NumDays = CInt(TS.TotalDays.ToString)
NumDays = NumDays - LeapYearDays
age = (NumDays / DaysInYear)
MsgBox("Number days: " + NumDays.ToString)
MsgBox("Age: " + age.ToString)
I would guess there is a better cleaner way of getting what I want. How do
I factor-in leap years without using a hard coded value like 10? In this
case I just sort guesstimated that there were two leap years for each 10
years of age.