Use Sugar Logic to display the difference between two dates in months

John Mertic —  September 23, 2013 — 5 Comments

Here’s a question that came out from one of our training consultants…

I am wondering if we can display the duration of a contract within months.

I’v added a custom field with this formula subtract(number($end_date),number($start_date))

But it calculates only the days e.g. 

1.1.2013 – 1.1.2014 = 0 

1.1.2013 – 2.2.2014 = 1 

I also tried it with the daysUntil formula but this formula also calculates rubbish.

Does anyone know if or how we are able to solve such a requirement?

Playing around with Sugar Logic more, we found the formula that doesn’t calculate rubbish ;-). Try this for size…


Thanks to my fellow Sugas for the nice tip!

John Mertic


John Mertic manages the strategic ISV alliances program for SugarCRM, having several years of techincal experience bringing solutions to market with several SugarCRM technology partners. A frequent conference speaker and an avid writer, he has been published in php|architect, IBM Developerworks, and in the Apple Developer Connection, and is the author of the book 'The Definitive Guide to SugarCRM: Better Business Applications' and the book 'Building on SugarCRM: Creating Applications the Easy Way'. He is also president of the OpenSocial foundation, guiding them in solving interoperability issues for enterprise application providers worldwide.

5 responses to Use Sugar Logic to display the difference between two dates in months


    It is really cool! But, what if the Sugar version is lower (per say 6.2.4)? Is there any way that we can make it compatible with all Sugar versions? I tried with Sugar 6.2.4 and it did not go through. The screen was partially blank (because it did not get daysUntil function).


    Is it possible to get SugarLogic to Evaluate on DetailView, from the testing i have done, you need to open and save a record, for a sugar logic field to update the value which is not much use for a field like Opportunity Age, Time since last contact etc, where once side of the evaluation is the system clock.



    In the past what we have done is populated the field in a retrieve logic hook for detail view, and process_record hook for the listview.


    Actually this is really cool. We have several customers wishing to calculate the difference in days between each change of the sales stage, This would do perfectly, thanks!

Leave a Reply

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

You are commenting using your 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