Link to home
Start Free TrialLog in
Avatar of IEHP1
IEHP1Flag 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.
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Avatar of IEHP1


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.
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.

Avatar of IEHP1


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.
Avatar of Helen Feddema
Helen Feddema
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can set up a Select Case statement to get your age groups, depending on the value of Age.
> 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.