Tuesday, December 9, 2014

Business/Working days in AX

Following job is to calculate business days/working days in AX using base calendars.

In my case base calendar name is "24/5" you can change it as per your setup.

static void businessdaysInPeriod(Args _args)
{
    WorkCalendarSched workCalendarSched;
    date start;
    date end;
    counter workingdays;
    counter totaldays;
    CalendarId primCalendar="24/5";
    ;

    start = str2date("21-11-2014",123);
    end   = str2Date("26-11-2015",123);

    workCalendarSched = new workCalendarSched();

    while(start<=end)
    {
        totaldays++;

        if(workCalendarSched.isdateopen(primCalendar,start)==true)
        {
            workingdays++;
        }
        start++;
    }

    info(strfmt("Total days: : %1",totaldays));
    info(strfmt("Total working days: : %1",workingdays));

}