Saturday, February 15, 2014

Days between two dates not counting Saturday and Sunday:

// Days between two dates not counting Saturday and Sunday:

static void WorkDayDiff(Args _args)
{
    int i;
    Days workDayDiff(date d1, date d2)
    {
        Days y1 = dayofwk(d1);          // Day of week 1
        Days y2 = dayofwk(d2);          // Day of week 2
        date t1 = d1 - y1;              // Sunday before d1
        date t2 = d2 - y2;              // Sunday before d2
        Days y3 = (t2 - t1) div 7 * 5;  // Work days between Sundays
        Days y4 = min(y1-1,5);          // Work days before d1
        Days y5 = min(y2,5);            // Work days after t2
        return y3 - y4 + y5 - 1;        // Work days between d1 and d2
    }
    ;
    setprefix(strFmt("Today %1 %2", today(), dayname(dayofwk(today()))));
    for (i = -10; i <= 10; i++)
        info(strFmt("Diff %1 %2 = %3", today()+i, dayname(dayofwk(today()+i)), int2str(workDayDiff(today(), today() + i))));
}

No comments:

Post a Comment

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...