Results 1 to 3 of 3
  1. #1
    JimO is offline Competent Performer
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    126

    DateDiff and age

    When using the DateDiff function to return a persons age it does not update the age for today. A person born on todays date (1/12/1957) turns 60 today (7/12/2016) but the expression returns the age as 59. I'm looking to have birthday ages that occur on todays date reflect the change.



    Code:
    DateDiff("yyyy",[DOB],Now())
    Jim O

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Here is another
    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. DateDiff
    By TheHarleygirl2005 in forum Access
    Replies: 2
    Last Post: 07-09-2015, 11:44 AM
  2. DateDiff
    By mphynson44 in forum Queries
    Replies: 3
    Last Post: 02-27-2014, 07:28 PM
  3. DateDiff
    By mrkaye in forum Forms
    Replies: 18
    Last Post: 11-19-2010, 08:19 AM
  4. DateDiff
    By ROB in forum Access
    Replies: 2
    Last Post: 10-30-2010, 03:58 AM
  5. Need Help with Datediff
    By gonzod in forum Access
    Replies: 5
    Last Post: 08-26-2010, 02:29 PM

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