SugarTip – Automatically Calculate the number of days between two dates

sugarcrmdevelopers —  March 14, 2012 — 1 Comment

This week SugarCRM Gold Partner EnableIT SugarUK‘s Mike Gee shows how you can use calculated fields to count the number of days between two specified dates.

One of the questions I was asked most as a result of my previous post Sugar Tip – Creating a calculated field to count days until a date was “How can I calculate the number of days between two date fields?”

As a result, here is the answer:

In order to achieve the calculation, you need to already have two date fields in your SugarCRM system. If you need to create these, they should be done in the Studio prior to creating the calculated field.

Create a new field in the Studio in the same module as the two date fields using an Integer field, clicking the “Calculated” tick-box and in the Formula Editor use the following calculation:

abs(subtract(daysUntil($datefieldA),daysUntil($datefieldB)))

where $datefieldA is the earliest date and $datefieldB is the later date.

e.g. To calculate the difference between the date a record was created and the last time it was modified, you would put the datecreated field string in$datefieldA and the datemodified string in $datefieldB.

This tip was originally posted on the EnableIT SugarUK Blogs where you can find a whole host of other useful SugarCRM tips.


Why not follow Mike on Twitter @EnableITmike or connect with him on LinkedIn

One response to SugarTip – Automatically Calculate the number of days between two dates

  1. 

    hi this will work in CE edition?
    tried to use this in logic hook (as below), but not working

    $daysbetween = abs(subtract(daysUntil($datefieldA),daysUntil($datefieldB)));

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s