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
Thanks it's working :)
Keep in mind that calculated fields are re-calculated only when you save the record, or by manually triggering the "Recalculate Values" in the List View Action Menu on a set of selected records, so if you have a record that has not been updated for a while the age will be wrong.
To keep the field up to date you have a few options:
I suppose you could make the last two DB fields that recalculate when the record is opened, but I think that would mean a LOT of unnecessary saves to your DB, and trigger the update of your Last Modified and Modified By every time one simply opens a record...
All in all, I would recommend against adding such a field. Just a personal preference.
FrancescaS
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
Hello
I wonder how it is supposed Sugar Logic to recalculate each all contact's age on a daily basis... That should be piece of work for a scheduled job, thought
Have you set your mind regarding the approach to use?
Best Regards,
Dmytro Chupylka
integroscrm.com
We make work in Sugar CRM system faster, more convenient and efficient
you are a genius!
Harald Kuske
Principal Solution Architect – Professional Services, EMEA
hkuske@sugarcrm.com
SugarCRM Deutschland GmbH