Calculate age in a previous period

gstylianou

Registered User.
Local time
Today, 14:21
Joined
Dec 16, 2013
Messages
359
Good Evening,
How can calculate the age was someone in a previous period. For example

Date of Birth: 01/01/2000
Posted: 01/01/2010

Should give a result of 10 years ...

Thank you very much
 
Search for 'Calculate Age' on this site, there have been plenty of posts asking the same thing.
I seem to recall arnelgp even did one in words?
 
Hi. And when you find one, it will probably use the Date() function to calculate the current age. All you have to do is replace Date() with the input date or period.
 
Code:
'arnelgp
Public Function Age(ByVal dteStart As Date, Optional ByVal dteEnd As Variant = 1)
If IsNull(dteEnd) Then dteEnd = Date
If dteEnd = 1 Then dteEnd = Date
Age = DateDiff("yyyy", dteStart, dteEnd) + (Format(dteStart, "mmdd") < Format(dteEnd, "mmdd"))
End Function

?Age([Date of Birth], [Posted])
 
Last edited:
Just watch out for the pitfalls of using DateDiff. If I compute a difference in years between my birth date and this year's day before my birthday, I'll be not quite 73 on that date. But if I compute the difference in days and divide by 365.2422, I could get a different number of years due to truncation and rounding issues. When dealing with whole days (no times) for starting and ending dates of the period in question, you should get a correct result truncated to the next lowest integer in the current units. Fractions won't count.
 

Users who are viewing this thread

Back
Top Bottom