Results 1 to 3 of 3
  1. #1
    earlcools is offline Novice
    Windows 8 Access 2010 32bit
    Join Date
    Jan 2015
    Posts
    2

    get age from date to birth

    I am using this DateDiff("yyyy", [DOB], Date()) to get the age however it seem to doing same kind of rounding error.

    for example today is 1/27/2015 using the above function I get 17 years I want to get 16 years.
    DOB Age
    5/12/1998 17


  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Yes, it is rounding to whole year because the criteria is yyyy. If you want more precision, will need to calculate days then divide by 365, which is still an approximation because not every year has 365 days.

    The result will be 16.7232876712329
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Here is a function to determine Age. It accounts for the Birthday and the current date.

    Code:
    '---------------------------------------------------------------------------------------
    ' Procedure : Age
    ' Author    : Jack (from awf)
    ' Date      : 06-09-2012
    ' Purpose   : This routine determines the Age of a Person given their DOB.
    ' It accounts for the birthday this year (whether passed or not). A second parameter
    ' Specdate allows you to work from a different Date than today's date.
    'If SpecDate is missing, the routine defaults to today's date.
    '---------------------------------------------------------------------------------------
    ' Last Modified:
    '
    ' Inputs: N/A
    ' Dependency: N/A
    '--------------------------------------------------------------------------
    '
    Public Function Age(dteDOB As Date, Optional SpecDate As Variant) As Integer
          Dim dteBase As Date, intCurrent As Date, intEstAge As Integer
    10       On Error GoTo Age_Error
    
    20    If IsMissing(SpecDate) Then
    30    dteBase = Date
    40    Else
    50    dteBase = SpecDate
    60    End If
    70    intEstAge = DateDiff("yyyy", dteDOB, dteBase)
    80    intCurrent = DateSerial(Year(dteBase), Month(dteDOB), Day(dteDOB))
    90    Age = intEstAge + (dteBase < intCurrent)
    
    100      On Error GoTo 0
    110      Exit Function
    
    Age_Error:
    
    120       MsgBox "Error " & Err.number & " (" & Err.Description & ") in procedure Age of Module AWF_Related"
    End Function

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

Similar Threads

  1. How to change date of birth into text
    By Ayiramala in forum Access
    Replies: 13
    Last Post: 12-28-2014, 09:21 PM
  2. Calculate age from Date of Birth
    By djcmalvern in forum Programming
    Replies: 8
    Last Post: 05-03-2013, 06:18 AM
  3. Date of birth converter
    By markyboy in forum Forms
    Replies: 1
    Last Post: 05-23-2011, 07:20 AM
  4. Date of Birth Access expression
    By Father John in forum Access
    Replies: 5
    Last Post: 12-02-2010, 10:33 PM
  5. Calculate age from birth date
    By mick in forum Forms
    Replies: 2
    Last Post: 07-03-2010, 04:31 PM

Tags for this Thread

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