Apr 13 2022 07:11 PM
Hi All,
Just got a question regarding calculating ages in tables in access. I am on Access 2016, and I have two columns, DOB, and Death Date. I only have one entry for a death date, and if there is not a death date I want to calculate it from today. Would I use a Calculated Field Type? What would I put in it?
I found some Vba code, but I don't know how to put that into my table.
Apr 13 2022 07:49 PM
Apr 14 2022 04:06 AM
Apr 16 2022 09:16 AM - edited Apr 16 2022 09:27 AM
AFAIK, the simplest expression for calculating age in years to the current date is:
Function AgeYears(DOB As Date) As Integer
AgeYears = DateDiff("yyyy", DOB, Date) + (Format(DOB, "mmdd") > Format(Date, "mmdd"))
End Function
It could easily be adapted to allow for date at death as above
Apr 16 2022 10:10 AM
You could even modify it to return either "age at death" or "current age", using a Iif() or Switch()....
Apr 16 2022 12:21 PM - edited Apr 17 2022 03:40 PM
You could indeed ...
Apr 19 2022 12:01 AM
For info, I've added a new page to my website Calculate Age (isladogs.co.uk).
It includes various functions to calculate age in years, years and months or years, months and days.
Calculations can be done to the current date or between two specified dates