Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Calculate Age from DOB

  • 04-02-2005 5:31pm
    #1
    Registered Users, Registered Users 2 Posts: 245 ✭✭


    Anybody know how to calculate an age from a given date of birth in vb.


Comments

  • Closed Accounts Posts: 92 ✭✭tempest


    In all fairness Third From The Top .

    Eitherways the algorithm to calculate it is pretty easy.
    If the solution above doesn't work then look up the DatePart function (I think, It's been a while), and sit down with a piece of paper and think about how to perform a difference between two dates.

    Subtract the date of birth year from the current year to get the difference in the years.

    If the date of birth month is less than the current month then
    "What do I do here"
    Otherwise if greater
    do something
    else
    do compare the days fields.


  • Closed Accounts Posts: 9,314 ✭✭✭Talliesin


    Private Function Age(ByVal DOB As Date) As Long
        Dim PastBirthday As Boolean
        Dim CurDate As Date
        CurDate = Now
        Select Case Month(DOB) - Month(CurDate)
            Case 0
                PastBirthday = Day(CurDate) >= Day(DOB)
            Case Is < 0
                PastBirthday = True
            Case Is > 0
                PastBirthday = False
        End Select
        If PastBirthday Then
            Age = Year(CurDate) - Year(DOB)
        Else
            Age = Year(CurDate) - Year(DOB) - 1
        End If
    End Function
    


  • Registered Users, Registered Users 2 Posts: 245 ✭✭Polonious


    Thanks Fella's


Advertisement