Calculate exact age

jessss

Registered User.
Local time
Today, 03:30
Joined
Jan 17, 2010
Messages
29
Calculate exact age - solved

Hi,

I am trying to find a way of calculating the exact of someone from their Date of Birth.

On my access form I have a text box with the date of birth and what I want to be able to do is have another box flag up whether from the dob the person is under 18 but as in if the person is going to be 18 this year but for a couple of months I want a text to flag up to say they are not 18 just yet.

Hope this makes sense! I have tried to calculate the exact age of someone down to the day and month but when I put a date of birth in as 01/06/1996 it keeps saying they are 18 but it should until the current date is 01/06/2014

Can anyone help me?? :confused:

Thanks!
 
Last edited:
I am not sure if this will be something you want; but I have this function in my code library. You can modify it, but please keep the credits intact.
Code:
Public Function exDateDiff(Date1 As Date, Date2 As Date) As String
[COLOR=Green]'***********************************
'Code Courtesy of
'  Paul Eugin
'   ? exDateDiff(#5/3/1989#, Date)
'     25 Years 0 Month and 19 days.
'***********************************[/COLOR]
    Dim totDays As Long, yVar As Long, mVar As Long, dVar As Long
    
    totDays = DateDiff("d", Date1, Date2)
    
    If Year(Date1) <> Year(Date2) Then
        While totDays > 365
            totDays = totDays - Val(Format(DateSerial(Year(Date1) + yVar, 12, 31), "Y"))
            yVar = yVar + 1
        Wend
    Else
        yVar = 0
    End If
    
    While totDays > 30
        totDays = totDays - DatePart("d", DateSerial(Year(Date1) + yVar, Month(Date1) + mVar + 1, 0))
        mVar = mVar + 1
    Wend
    
    dVar = totDays
    
    exDateDiff = yVar & IIf(yVar <= 1, " Year ", " Years ") & _
                 mVar & IIf(mVar <= 1, " Month and ", " Months and ") & _
                 dVar & IIf(dVar <= 1, " Day.", " Days.")
End Function
 
Hi, Thank you for your help. pr2-eugin function works great thank you!!
 
You're welcome, although if you want just the age, I would say you could use the Listing 2.23: A Second Solution for Calculating Age. From the link provided by CJ !
 

Users who are viewing this thread

Back
Top Bottom