Age Calculated Date when end date is empty

I am looking to create a calculated age field (integer).  I am new to Sugar so I don't know how to craft the formula.  It would look at two date fields (start date field and an end date field) and use today's date if necessary.  I would like the age field to work as follows:

If start date field is empty then age should be empty

Else If end date is empty then today's date - start date

Else end date - start date

  • Hi  ,

    To do an aging formula, you will use the ifElse formula to determine whether you end date field is populated and then perform your calculation based on that result. The formula would look like the following:

    ifElse(
        equal(
            $end_date,
            ""
        ),
        subtract(
            0,
            daysUntil(
                $start_date
            )
        ),
        subtract(
            daysUntil(
                $end_date
            ),
            daysUntil(
                $start_date
            )
        )
    )

    There are a few caveats to keep in mind with this approach because Sugar Logic formulas are re-evaluated each time the record is saved:

    1. If at least one of your fields is a datetime field, you can potentially get fluctuating calculations depending on when the datetime value occurred. For instance, if you use the date_entered field as your start date, then you may see variations on the start date depending on when it was created and who last saved the record. If a user in the eastern time zone created a record at 12:30 AM on October 21st, the formula will see the start date as 10/21 when the eastern time user saves the record but the formula will see it as 10/20 when a central time user saves the record. For calculating an integer value of days a record was open, it is recommended to use two date fields for these calculations to avoid these discrepancies. You can use SugarBPM to populate the date field on record creation with the current date.
    2. Sugar Logic fields only recalculate on record saves so this solution will not give you an accurate record age for open records unless you are resaving those records in some fashion on a daily basis. We offer a plugin, Upsert Calculated Fields, which allows you to configure modules to be recalculated. Calculating record age is one of the most often reasons customers use our plugin. Please let contact us if you would like a demo!

    I hope this helps!

    Chris