Results 1 to 4 of 4

Thread: Age calculation

  1. #1
    Star Lounger
    Join Date
    Jun 2002
    Location
    London, Gtr London, England
    Posts
    75
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Age calculation

    I am using the following function to work out the age of someone.

    DateDiff("yyyy", DOB, Date)

    The DateDiff calculation does not look at partial months, ie dob 12/05/90 will produce an age of 11 even though they are only 10. Can anyone help??

  2. #2
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    USA
    Posts
    386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Age calculation

    Try this function

    Function Age(Bdate, DateToday) As Integer
    ' Returns the Age in years between 2 dates
    ' Doesn't handle negative date ranges i.e. Bdate > DateToday

    If Month(DateToday) < Month(Bdate) Or (Month(DateToday) = _
    Month(Bdate) And Day(DateToday) < Day(Bdate)) Then
    Age = Year(DateToday) - Year(Bdate) - 1
    Else
    Age = Year(DateToday) - Year(Bdate)
    End If
    End Function


    Good luck

    Richard Aheron
    raheron@hotmail.com
    [img]/w3timages/icons/grin.gif[/img]
    Richard

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Tennessee
    Posts
    194
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Age calculation

    i put this code in the oncurrent event
    yourTextbox = DateDiff("yyyy", [BirthDate], Now()) + Int(Format(Now(), "mmdd") < Format([BirthDate], "mmdd"))
    hope it helps
    JerryC

  4. #4
    dennyryan
    Guest

    Re: Age calculation

    If you just want an integer value this would give you a pretty good approximation:

    int((Date - DOB)/365)

    Denny

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •