How to find out someone's age from a Date Of Birth in VB?

How can I find someones age from their date of birth in VB

Any help would be appreciated

4 Answers

Relevance
  • Anonymous
    1 decade ago
    Favorite Answer

    Public Function GetAgeInYears(ByVal Birthdate As Date, Optional ByVal AsofDate As Variant) As Long

    If IsMissing(AsofDate) Then AsofDate = Now

    GetAgeInYears = DateDiff("yyyy", Birthdate, AsofDate)

    If Month(AsofDate) < Month(Birthdate) Then

    GetAgeInYears = GetAgeInYears - 1

    ElseIf Month(AsofDate) = Month(Birthdate) Then

    If Day(AsofDate) < Day(Birthdate) Then

    GetAgeInYears = GetAgeInYears - 1

    End If

    End If

    If GetAgeInYears < 0 Then

    GetAgeInYears = 0

    End If

    End Function

  • 1 decade ago

    You can use DateDiff, and DateAdd to easily calculate time spans between 2 date variables.

  • 1 decade ago

    take the year 2008 and subtract the birth year.

    if you haven't reached the month yet, then subtract a year.

  • Don M
    Lv 7
    1 decade ago

    alex did you sleep in math class.

    simple addition and subtraction

Still have questions? Get your answers by asking now.