Many times we come across a requirement where you require to calculate the number of months between two Dates. In our blog, we will explain how you can achieve this.
Lets, take an example where we need to calculate the difference of months between two date fields. Here we have created Start Date and Close Date fields against the company entity to find the age of the company in months.
First step is to create 3 new fields against company as displayed in above image.
- Navigate to below path
<<Sage CRM Installation Directory>>\ \<<CRMINSTANCENAME>>\WWWRoot\js\custom
- Create a new js.file and insert the below code
var sStartDate = document.getElementById('claus_start_date').value; var sCloseDate = document.getElementById('claus_close_date').value; var sDate = sStartDate.substring(0, 2); var sMonth = sStartDate.substring(3, 5); sMonth--; var sMon = sMonth; var sYear = sStartDate.substring(6, 10); var sDate1 = sCloseDate.substring(0, 2); var sMonth1 = sCloseDate.substring(3, 5); sMonth1--; var sMon1 = sMonth1; var sYear1 = sCloseDate.substring(6, 10); var FormattedStartDate = new Date(sYear, sMon, sDate); var FormattedCloseDate = new Date(sYear1, sMon1, sDate1); var Diff = FormattedCloseDate-FormattedStartDate; var DiffDays = Math.ceil(Diff / (1000 * 60 * 60 * 24)); var DiffMonths = Math.floor(DiffDays / 30); claus_diff_months.value = DiffMonths;
- Log on to Sage CRM
- Navigate to below path
Administration | Customization
- Choose the entity and navigate to screen.
- In On change script of Close Date field, add the required function.
Once you are done you should find the months calculated for the entered dates. Hope this information helps!
Greytrix – a globally recognized and one of the oldest Sage Development Partners is a one-stop solution provider for Sage ERP and Sage CRM organizational needs. Being acknowledged and rewarded for multi-man years of experience and expertise, we bring complete end-to-end assistance for your technical consultations, product customizations, data migration, system integrations, third-party add-on development, and implementation competence.
Greytrix has some unique integration solutions developed for Sage CRM with Sage ERPs namely Sage X3, Sage Intacct, Sage 100, Sage 500, and Sage 300. We also offer best-in-class Sage ERP and Sage CRM customization and development services to Business Partners, End Users, and Sage PSG worldwide. Greytrix helps in the migration of Sage CRM from Salesforce | ACT! | SalesLogix | Goldmine | Sugar CRM | Maximizer. Our Sage CRM Product Suite includes addons like Greytrix Business Manager, Sage CRM Project Manager, Sage CRM Resource Planner, Sage CRM Contract Manager, Sage CRM Event Manager, Sage CRM Budget Planner, Gmail Integration, Sage CRM Mobile Service Signature, Sage CRM CTI Framework.
Greytrix is a recognized Sage Champion Partner for GUMU™ Sage X3 – Sage CRM integration listed on Sage Marketplace and Sage CRM – Sage Intacct integration listed on Sage Intacct Marketplace. The GUMU™ Cloud framework by Greytrix forms the backbone of cloud integrations that are managed in real-time for the processing and execution of application programs at the click of a button.
For more information on our integration solutions, please contact us at email@example.com. We will be glad to assist you.