# Calculate A Persons Age

How do i compute a persons age? if there's a leap year?
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

IT Project ManagerCommented:
IT Project ManagerCommented:
This is from a PAQ:  http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20626567.html

Private Sub Command1_Click()
'2003 05 26_
'1976 10 31
'--------------
'     26 06 25

Dim dtm1 As Date
Dim dtm2 As Date
Dim intYear As Integer
Dim intMonth As Integer
Dim intDay As Integer

dtm1 = #5/26/2003#
dtm2 = #10/31/1976#

intYear = Abs(Year(dtm2) - Year(dtm1))
If (Month(dtm1) < Month(dtm2)) Or ((Month(dtm1) = Month(dtm2)) And (Day(dtm1) < Day(dtm2))) Then
intYear = intYear - 1
End If

If Month(dtm1) > Month(dtm2) Then
intMonth = Month(dtm1) - Month(dtm2)
Else
intMonth = (12 - Month(dtm2)) + Month(dtm1)
If Day(dtm1) < Day(dtm2) Then
intMonth = intMonth - 1
End If
End If

If Day(dtm1) > Day(dtm2) Then
intDay = Day(dtm1) - Day(dtm2)
Else
intDay = (30 - Day(dtm2)) + Day(dtm1)
End If

MsgBox intYear & "-" & intMonth & "-" & intDay
End Sub

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
test for leap year

Public Function IsLeapYear(Yr As Integer) As Boolean

'Set default return value
IsLeapYear = False

'If year is divisible with four then it's a leap year, unless
'is divisible by 100 but not by 400...
If Yr Mod 4 = 0 Then

IsLeapYear = True

If Yr Mod 100 = 0 Then

If (Yr Mod 400) Then IsLeapYear = False

End If

End If

End Function
IT Project ManagerCommented:
Why the 'B' grade?  I supplied two working links and one with source code.
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.