Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2014
    Posts
    5

    I am trying to calculate a persons age from DOB to a specific year afer "Enter date"

    I have created the extra field in my query for "Age" but I can't seem to be able to calculate it to show me in years. I am very new at this, I have tried Date(Now()-[DOB]) and other examples from different sites and have no luck

    can someone please assist me with this



    Regards
    Don

  2. #2
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614

  3. #3
    Join Date
    Feb 2014
    Posts
    5
    Thank you 'amrut' that was very helpful I'm now on the right track. I tried DateDiff("yyyy",[Dob],Date()) and it gave me the Age as of this year but if I type in another year it still comes up with this years age. Any suggestions to fix this

    regards
    Don

  4. #4
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    but if I type in another year it still comes up with this years age.
    How do you type another year ? Further, remember that access calculates all dates based on US date format of mm/dd/yyyy irrespective of your PC's date format.

  5. #5
    bayoeth is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2017
    Posts
    2
    Quote Originally Posted by don1.delinquent View Post
    Thank you 'amrut' that was very helpful I'm now on the right track. I tried DateDiff("yyyy",[Dob],Date()) and it gave me the Age as of this year but if I type in another year it still comes up with this years age. Any suggestions to fix this

    regards
    Don
    Hi,here's what i found in the internet for computing the Age.

    In your table, create an Age Field. Go to design view and make it a Calculated Field. On the Expression, type ([Your Desired Date]-[Dob])*4/1461

    After that, create another Field to Round Down the Age. On the Expression type Left([Age],2)

    That formula somehow worked for me, the only problem would be it's rounded to nearest Year, and you'll get Zeros for those who are less than 1 year old.
    Another Problem I found is that there are instances when it calculates 1 year less than the Age. For example DoB is 4/18/1952 and Future Date is 4/18/1957, it returns only 4 (or 4.99 if you did not use 0 for the decimal format in your report). i don't know why that happens

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I use a function to calculate ages.
    Code:
    Function GetAge(varDOB As Variant, Optional varAsOf As Variant) As Variant
       'Purpose:   Return the Age in years.
       'Arguments: varDOB = Date Of Birth
       '           varAsOf = the date to calculate the age at, or today if missing.
       'Return:    Whole number of years.
       Dim dtDOB As Date
       Dim dtAsOf As Date
       Dim dtBDay As Date  'Birthday in the year of calculation.
    
       GetAge = Null          'Initialize to Null
    
       'Validate parameters
       If IsDate(varDOB) Then
          dtDOB = varDOB
    
          If Not IsDate(varAsOf) Then  'Date to calculate age from.
             dtAsOf = Date
          Else
             dtAsOf = varAsOf
          End If
    
          If dtAsOf >= dtDOB Then      'Calculate only if it's after person was born.
             dtBDay = DateSerial(Year(dtAsOf), Month(dtDOB), Day(dtDOB))
             GetAge = DateDiff("yyyy", dtDOB, dtAsOf) + (dtBDay > dtAsOf)
          End If
       End If
    End Function
    Usage can be on a form. In a text box, I have
    Code:
    =Getage([Forms]![employee details]![end_dob],[Forms]![startup]![viewdate])
    or you can use the function in a query......

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 01-11-2014, 11:57 PM
  2. Replies: 7
    Last Post: 07-19-2013, 11:58 AM
  3. Replies: 2
    Last Post: 11-26-2012, 11:12 PM
  4. Replies: 2
    Last Post: 09-29-2012, 11:22 PM
  5. Replies: 4
    Last Post: 03-14-2012, 09:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums