function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Blake Carrera 4Blake Carrera 4 

Date Field Calculation for Months with 31 Days

We currently have three fields that should work based off of each other:

Contract Term
Start Date 
End Date

If the start date and terms are populated, the end date should automatically populate. We've figured this one out. 

What we haven't figured out if how to populate the Contract Term with the correct number (12 for example in the case of a year) if the start date and end date are populated. The problem seems to be because some months have 31 days. Does anyone have any idea how to write a formula that would work for this?
AbhishekAbhishek (Salesforce Developers) 
Hi Blake,

Your query is answered in this blog,

https://getawayposts.com/add-months-date-salesforce-formula-addmonths-function

Check it and use the formula as mentioned.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks.
Blake Carrera 4Blake Carrera 4
Abishek-

That helps a lot. I was wondering if you had any idea for this situation however. If I use that, it will calculate the exact number of months. This works correctly. However, an ideal situation has emerged in which it would calculate 364 days in advance. Here is an example:

Start Date: 3/31/2020
End Date: 3/30/2021
Term: 12

While I know I could add 364 days, is there a way to do this but still display the term in months?
AbhishekAbhishek (Salesforce Developers) 
Sorry, Balke, I don't any further more suggestions.