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
MohandaasMohandaas 

Difference between two date values

When I subtract (End Date - Start Date) the result is a number of days. Is there a formula to get the result in terms of months?

 

Appreciate your help.

iSqFt_ADiSqFt_AD

You could divide the result  by 30 or 30.41666 (average days in a month) and use it as a very close estimate. I am sure you could devise a "table" of days in each month that could figure out if the month of the start date is July it has 31 days and the end date is December and has 31 days, but in the end you are converting a number of days into months and the average month has 30.14666 days in it.

SAPOCSAPOC

You can use the formula Month(End Date)-Month(Start Date).

sfdcfoxsfdcfox

SAPOC, your formula is very close, but you forgot to account for years:

 

 

(YEAR(EndDate__c  )*12+MONTH(EndDate__c  ))-
(YEAR(StartDate__c)*12+MONTH(StartDate__c))

We convert years into months (i.e. multiply by 12), then add the month to this value. This allows for yearly rollovers, such as Dec 2010-Jan 2011 is one month, not -11 months, and multiple years, such as June 2009-June 2011, which is 24 months, not zero months.

 

KMKKMK

 

StartDate__c.monthsBetween(EndDate__c)

Try this. It will works fine to find the months differnece between two dates.
If you want Day level difference you use "daysBetween" instead of "monthsBetween"