Hello, does anyone know Sugar Logic formula to calculate age based on a Birthdate date field.
Thank you
Hello, does anyone know Sugar Logic formula to calculate age based on a Birthdate date field.
Thank you
Hi Jean,
Create a field for the Age with integer data type and make it a calculated field through the studio.
By using the below formula you can calculate the Age.
floor(divide(abs(daysUntil($birthdate)),365))
Hope this helps you and you are looking for the same.
Thanks,
Poojitha K
This is only an approximate figure. E.g. according to the formula someone who was born on March 3rd, 1958 is already 63 years old on February15th, 2021 (two weeks too early). If you want it exactly you have to take the leap years into account.
But still a damn good formula. :-)
PS: I think the full formula could be:
floor(divide(subtract(abs(daysUntil($birthdate)),floor(divide(subtract(year(today()),year($birthdate)),4))),365))
Harald Kuske
Principal Solution Architect – Professional Services, EMEA
hkuske@sugarcrm.com
SugarCRM Deutschland GmbH
Harald Kuske thanks for your alternate version, certainly shorter than the one mentioned here:
add(subtract(number(subStr(toString(today()),12,4)),number(subStr(toString($birthdate),6,4))),ifElse(greaterThan(monthofyear($birthdate),monthofyear(today())),-1,ifElse(greaterThan(monthofyear(today()),monthofyear($birthdate)),0,ifElse(greaterThan(subtract(number(subStr(toString(today()),5,2)),number(subStr(toString($birthdate),3,2))),-1),0,-1))))
.
CRM Business Consultant
Haha, I did not see that other formula...
In Sugar you always have two possible solutions....
Harald Kuske
Principal Solution Architect – Professional Services, EMEA
hkuske@sugarcrm.com
SugarCRM Deutschland GmbH
Actually, looking into this a little more, can shorten it and be similar precision (passes your test) with just this version?
floor(divide(abs(daysUntil($birthdate)),365.242))
.
CRM Business Consultant
Actually, looking into this a little more, can shorten it and be similar precision (passes your test) with just this version?
floor(divide(abs(daysUntil($birthdate)),365.242))
.
CRM Business Consultant
you are a genius!
Harald Kuske
Principal Solution Architect – Professional Services, EMEA
hkuske@sugarcrm.com
SugarCRM Deutschland GmbH