Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Microsoft: Access Other topics FAQ

Access Howto:

How to calculate age (another method). by elizabeth
Posted: 20 Jun 00

The following commonly-used function fails on a small percentage of dates; the specific failure dates depend on the birth date and current date.

Function Age(Birthdate as Date) as Integer
    Age = Datediff("d", Birthdate, Date) / 365.25
End Function

Instead try this:

Function Age (Birthdate as Date) as Integer
    Age = DateDiff("yyyy", Birthdate, Date) + _
             (Date < DateSerial(Year(Date), Month(Birthdate), Day(Birthdate)))
End Function

This takes advantage of the fact that True has a value of -1 and False has a value of 0... If this expression is True (the birthdate in the current year hasn't happened yet), you end up subtracting 1 day.

If you want to enter your own end date instead of using today's date, here is the modification:

Function Age(Birthdate As Date, Enddate as Date) As Integer
    Age = DateDiff("yyyy", Birthdate, Enddate) +  _
             (Enddate < DateSerial (Year(Enddate), Month(Birthdate), Day(Birthdate)))
End Function

- Mostly from an article by Ken Getz in MS Office & VB Developer Mag, p.64

Back to Microsoft: Access Other topics FAQ Index
Back to Microsoft: Access Other topics Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close