web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :

ISO Week number

DaxNigel Profile Picture DaxNigel 2,574

The standard AX system when it return the week number is based on the european standard. If you need an ISO week number control, then you will need to add some code. To make this work you need to add two new global functions to the global class:

static int weeksinyear(transdate _curdate )
{
    int iYear;
    int iweek;
    int iweek2;

    iYear = year(_curDate);

    iweek = dayOfYr(_curDate);

    iweek = real2int((iYear + (iYear / 4) - (iYear / 100) + (iYear / 400)) MOD 7);
    iYear = iYear - 1;
    iweek2 = real2int((iYear + (iYear / 4) - (iYear / 100) + (iYear / 400)) MOD 7);

    if(iweek == 4 || iweek2 == 3)
    {
        return 53;
    }

    return 52;
}

and

static int weeknumberISO(date _curDate)
{
    int iYear;
    int iweek;
    int iweeksinyear;
    int ireturn;

    iYear = year(_curDate);

    iweeksinyear = weeksinyear(_curdate);

    iweek = real2int((dayOfYr(_curDate) - dayOfWk(_curDate) + 10) / 7);

    if(iweek < 1)
    {
        ireturn = iweeksinyear - 1;
    }
    else if(iweek > iweeksinyear)
    {
        ireturn = 1;
    }
    else
    {
        ireturn = iweek;
    }

    return ireturn;
}

To use the new function, simple send the call the function with the date and it will return the week number to ISO standards.


This was originally posted here.

Comments

*This post is locked for comments