fonction or module to calculate age in year months days access 2003

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • johanneguaybenoit
    New Member
    • Mar 2008
    • 1

    fonction or module to calculate age in year months days access 2003

    Hi

    I would like to know how to create a function or module to calculate
    the age of a person in years months days.

    and hours if feasable
    But I really nead to know in years months days.
    I am waiting a reply from you and many thanks for your help in advance.
    Johanne
  • Scott Price
    Recognized Expert Top Contributor
    • Jul 2007
    • 1384

    #2
    Johanne,

    Have a look at this link.

    Regards,
    Scott

    Comment

    • missinglinq
      Recognized Expert Specialist
      • Nov 2006
      • 3533

      #3
      For doing any calculation of this type, you have to calculate the difference between the two values (in this case the DOB and today) in the lowest common denominator. For dates that would be days. So you start out by using the Access native function DateDiff(), using "d" as the interval.

      DaysDiff = DateDiff("d", [DOB], Date)

      So now you have the age in days. Next you need to parse the number of years/months/weeks/days from this number, and therein lies the problem! How many days are in a year, 365 or 366? How many days are in a month, 28, 29, 30 or 31? Most people doing this sort of thing elect to use 365 days per year and 30 days per month. Doing this will give you a very high degree of accuracy. But extending this to weeks and days, the results are going to be inaccurate, and the older the person is, the more inaccurate the results are going to be.

      Here's code to give you Years/Months; if you want to go further, heeding the above warnings, you can use this as a guide. It assumes the date of birth is entered in a textbox named DOB and calculates the age when you exit the control.

      Code:
      Private Sub DOB_AfterUpdate()
      
      DaysDiff = DateDiff("d", [DOB], Date)
      
      years = Int(DaysDiff / 365)
      days = DaysDiff Mod 365
      
      months = Int(days / 30)
      days = days Mod 30
      
      Me.AgeInYearsMonths = years & " Year(s) and " & months & " Month(s)"
      
      End Sub
      Welcome to TheScripts!

      Linq ;0)>

      Comment

      Working...