Avatar of IEHP1
Flag for United States of America asked on

Age function

So I have a date/time field for the birth date called birth. I need to create a function that will calculate a person's age as of the present time. Please let me know if you can help.
Microsoft ApplicationsMicrosoft OfficeMicrosoft Access

Avatar of undefined
Last Comment
Gustav Brock

8/22/2022 - Mon
Gustav Brock


I'm not sure if that really helps out what I am trying to do. I created a VBA module and pasted in the code, then tried putting in the field as Age: AgeSimple([birth]) since it is one of the fields in the query.

I am trying to pull this information into the data pull for a query. I believe first I would need to convert the number of years, months, days from their birthdate to the present time (the number of months or months and days from birthday) (how many months from their birthday so that I can in a subsequent step, create a nested IIf statement for the age groups).....

Please let me know if you are understanding what I am trying to do. Thank you.
Gustav Brock

You did it right:

Age: AgeSimple([birth])

There is nothing more in it, except if you fields of Birth with Null value. If so, filter those out.

Your help has saved me hundreds of hours of internet surfing.

Actually, Expr2: DateDiff("d",[birth],Date()) is what will give me the number of days from their birthdate. So now I will have to create the nested IIf statement for the age groups based on my results from that query.
Helen Feddema

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Helen Feddema

You can set up a Select Case statement to get your age groups, depending on the value of Age.
Gustav Brock

> So now I will have to create the nested IIf statement for the age groups based on my results

No, that won't work because years are not of the same count of days. Neither will the method using DateSerial do as it doesn't take leaplings (those born on Feb. 29th) in account.
You have to use DateAdd as shown above in the function AgeSimple to get it 100% right.

You don't specify your age groups, but if they are decades you can do:

AgeGroup: 1 + AgeSimple([birth]) \ 10

Note the use of backslash to get an integer result for all ages.

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.