≡ Menu

Dynamics Ax 2012 : Number of months between two dates

Recently I got small problem to calculate no of months between two dates. Dynamics Ax 2012 provides a default function which calculates no of intervals between two dates based on enumeration.

int intvNo(date input_date, date ref_date, int func)

 

You can use it as

 

noOfIntervals = intvNo(refDate, inputDate, intvScale::Month);

 

intvScale enumation have two values for months

  • Month
  • YearMonth

 

If we provide the intvScale::Month then X++ ignores the year and assumes that month is calculated within one year.

If we provide the intvScale::YearMonth then X++ calculate the number of months between different years. Consider following example.

 

static void NumberofMonthsbetweenTwodates(Args _args)

{

date inputDate = str2Date("1/1/2007", 213);

date refDate = str2Date("3/1/2009", 213);

int noOfMonths,noOfMonthsBetweenYears;

;

noOfMonths = intvNo(refDate, inputDate, intvScale::Month);

noOfMonthsBetweenYears = intvNo(refDate, inputDate, intvScale::YearMonth);

//  noOfMonths= intvNo(firstdate,seconddate,IntvScale::Month);

print("noOfMonths  :"+int2str(noOfMonths) + "  ,noOfMonthsBetweenYears  :"+int2str(noOfMonthsBetweenYears));

}

Info box will be return like

noOfMonths  :2  ,noOfMonthsBetweenYears  :26

Comments on this entry are closed.