Number of months between two dates in Dynamics ax 2012

Recently 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(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.

There is another way to Calculates the difference between two dates in month units in Dynamics ax 2012 using method InfAdjValidation_MX::monthDifference(FromDate _fromDate, ToDate _toDate)

Advertisements

4 Responses to Number of months between two dates in Dynamics ax 2012

  1. rohit says:

    static void Job32(Args _args)
    {

    int OfIntervals;

    date inputDate,refDate;

    inputDate=21\11\1990;
    refDate= 21\11\1998;

    OfIntervals = intvNo(refDate, inputDate, intvScale::Month);
    info(strFmt(“%1”,OfIntervals));
    }

    i wrote this code but it shows the answer as zero why ?? any idea……………..

    • Amir Nazim says:

      You have to select intvScale as intvScale::YearMonth, if you select Month in that, it just give to difference with in the same year, for your case needed the next value.

  2. rohit says:

    thanks issue resolved waiting for new code to be published……

  3. shweta says:

    Really it also helped me alot 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: