You need to sign in to do that
Don't have an account?

Months between two dates
In my trigger i would like to calculate the number of months between two date.
For Example if the date format is (DAY/MONTH/YEAR):
START DATE : 07/10/2013
END DATE: 12/01/2014
Number Months=4
because (07/01/2014) plus 1 month for the 5 days
I've tried with many examples, but nothing.
Please can you help me?
Thanks in advantage for any advice.
BR
You can use methods of Date class for calculating the number of days and months between two dates.
Please refer: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_date.htm
An example:
integer numberOfDays = startDate.daysBetween(endDate);
integer numOfMonths = Integer.valueOf(numberOfDays/30);
Or you can directly get no of months:
integer numberOfMonths = startDate.monthsBetween(endDate);