I got a situation where I need to calculate the number of months between 2 dates, I found a built in method in dynamics ax 2012 that can be used.
noOfIntervals = intvNo( inputDate,refDate, intvScale::Month);
intvScale enumation have two values for months
◾Month (X++ ignores the year and assumes that month is calculated within one year)
◾YearMonth ( X++ calculate the number of months between different years)
Another way to Calculates the difference between two dates in months in Dynamics ax 2012 is by using this method