How to calculate age based on Birthdate field

Hello, does anyone know Sugar Logic formula to calculate age based on a Birthdate date field.

Thank you

Parents
  • 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:

    • A Scheduler that updates  the field on all your records on a regular basis, could run once a month, for example, and check all birthdays that month to recalculate and update their age. This will allow you to store the age and use it in Reports.
    • A non-db field of a custom type where the value is calculated in the field's controller when the field is displayed
    • A non-db field that is calculated in the after-retrieve logic hook (note that this will NOT populate the age when you are creating a new record, because the after-retrieve does not trigger when displaying the results of creating a brand new record).

    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

Reply
  • 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:

    • A Scheduler that updates  the field on all your records on a regular basis, could run once a month, for example, and check all birthdays that month to recalculate and update their age. This will allow you to store the age and use it in Reports.
    • A non-db field of a custom type where the value is calculated in the field's controller when the field is displayed
    • A non-db field that is calculated in the after-retrieve logic hook (note that this will NOT populate the age when you are creating a new record, because the after-retrieve does not trigger when displaying the results of creating a brand new record).

    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

Children
No Data