Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Access - Age Calculator

Status
Not open for further replies.

OddJob

Technical User
Jul 26, 2001
1
GB
I need to create a Control that displays a persons age in years, months and days and will continue updating on a daily basis. The input information will be in the form of the persons date of birth and will compair this to todays date. Can anyone please help. Cheers.
 
Look at DateSerial and Datediff functions.
and The Format function
DougP, MCP

Visit my WEB site to see how Bar-codes can help you be more productive
 
this has been fairly extensively discussed in several threads in the Ms. Access and VB forums. I suggest that you search for Birthdays.

MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
Hmmmmmmmmmmmmm,

Slow Tuesday.

Code:
Public Function basYrsMnthsDays(DOB As Date) As String

    Dim Yrs As Integer
    Dim Mnths As Integer
    Dim Days As Integer
    Dim BdFlg As Boolean

    Yrs = DateDiff("yyyy", DOB, Now)
    Mnths = DateDiff("m", DOB, Now) Mod 12


    Select Case Month(DOB)
        Case Is < Month(Now)        'Not yet to this years B. Day

        Case Is = Month(Now)        'Correct Month.  check day
            Select Case Day(DOB)
                Case Is > Day(Now)  'Not there - YET
                    Yrs = Yrs - 1
                    Mnths = 11

                Case Is = Day(Now)  'Special!  this IS the BD
                    basYrsMnthsDays = CStr(Yrs) & &quot; Exactly!&quot;
                    BdFlg = True

                Case Is < Day(Now)  'Just Past it!  All Default Calcs are O.K.

            End Select

        Case Is > Month(Now)
            Yrs = Yrs - 1

    End Select
    
    If (Not BdFlg) Then
            Days = Day(DateSerial(Year(DOB), Month(DOB) + 1, 0) - Day(DOB))
            Days = Days + Day(Now)

            basYrsMnthsDays = CStr(Yrs) & &quot; Years, &quot; & CStr(Mnths) & &quot; Months, and &quot; & Days & &quot; Days&quot;
    End If

End Function
MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top