cancel
Showing results for 
Search instead for 
Did you mean: 

How to properly calculate age?

Verakso
Participant
0 Kudos

I wonder what is the best method for doing an age calculation?

I have a Birthday date in my dataset, and I would like to calculate how old the are at the current time when the file is running, e.g.


Year(CurrentDate()) - Year({Birthday})

The problem with the one above is, that it show the age of the persons in the current year, even though it might not have been their birthday yet.

I am missing the DateDiffInYears function but if I use this


Round(DateDiffInDays({Birthday}, CurrentDate()) / 365, 0)

I am still not getting the right results for some of the birthdays and the above assumption does not take leap years into consideration.

So even though Lumira has some powerful calculation, I still think some functions are missing, and I have so far no idea on how to do this calculation proper in Lumira

In Excel I can use


=DATEDIFF(Birthday;TODAY();"y")

to get the correct number of years, so how to do the same in Lumira?

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Thomas,

A really interesting question! On googling on how to do this through code, I came across this interesting Stackoverflow answer: algorithm - How can I calculate the age of a person in year, month, days? - Stack Overflow. I implemented just the years part in the formula editor and it seems to work pretty well. Here it is:


if Day(CurrentDate()) >= Day({Birthday}) then Floor(DateDiffInMonths({Birthday}, CurrentDate()) / 12) else Floor((DateDiffInMonths({Birthday}, CurrentDate()) - 1) / 12)

I know it looks really long, but it looks like it's doing the job. I tested it with only two dates: 6/5/1993 and 8/30/2008. It returns 23 and 7, which are correct answers. (CurrentDate() is 8/29/2016 when tested)

Let me know if it handles your corner cases! If it does, then full credits to the Stackoverflow answer!

Regards,

Maaz

Answers (2)

Answers (2)

varunanand
Contributor
0 Kudos

Hi Thomas,

There are several approaches to achieve this through if-then-else statements.

if (Month(CurrentDate()) < Month({Birthdate})) or (Month(CurrentDate()) = Month({Birthdate}) and Day(CurrentDate()) < Day({Birthdate})) then (Year(CurrentDate()) - Year({Birthdate}) - 1) else (Year(CurrentDate()) - Year({Birthdate}))

This one takes care to show year difference based on current month and date.

Please let me know if there are any questions or comments.

Thank you,

Varun Anand

TammyPowlas
Active Contributor
0 Kudos

What if you divided by 365.2425 instead of 365?  See

Formula to calculate Age in years and months - Salesforce Developer Community