wkOfYr Function [AX 2012]

Updated: December 11, 2009

Applies To: Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012

Calculates the week of the year in which a date falls, according to the ISO 8601 specification.


int wkOfYr(date _date)

Parameter

Description

_date

The date for which to calculate the week of the year.

The sequence number of the week in which the _date occurs.

The following code example compares the wkOfYr function with the Global::weekOfYear method. The two produce different results.

// X++ job, under AOT > Jobs.
static void WeekTests3Job(Args _args)
{
    int weekNum, i;
    date dateTest;
    str sMessages[];

    //---------------------------------------------
    sMessages[1] = "----- #1.  For Sunday, January 5, 2003 -----";
    dateTest = 5\1\2003; // Day\Month\Year  format.
    
    weekNum = wkOfYr(dateTest);
    sMessages[2] = int2str(weekNum) + " = wkOfYr funtion";
    weekNum = Global::weekOfYear(dateTest);
    sMessages[3] = int2str(weekNum) + " = Global::weekOfYear method";

    //---------------------------------------------
    sMessages[4] = " ";
    sMessages[5] = "----- #2.  For Wednesday, August 20, 2003 -----";
    dateTest = 20\8\2003;
    
    weekNum = wkOfYr(dateTest);
    sMessages[6] = int2str(weekNum) + " = wkOfYr funtion";
    weekNum = Global::weekOfYear(dateTest);
    sMessages[7] = int2str(weekNum) + " = Global::weekOfYear method";

    //---------------------------------------------
    sMessages[8] = " ";
    sMessages[9] = "----- #3.  For Sunday, December 28, 2003 -----";
    dateTest = 28\12\2003;
    
    weekNum = wkOfYr(dateTest);
    sMessages[10] = int2str(weekNum) + " = wkOfYr funtion";
    weekNum = Global::weekOfYear(dateTest);
    sMessages[11] = int2str(weekNum) + " = Global::weekOfYear method";

    for (i=1; i<= 11; i++)
    {
        Global::info(sMessages[i]);
    }
}

The previous code example sent the following information to the Infolog for display. The output shows that there are differences between wkOfYr and Global::weekOfYear.

Message (01:59:13 pm)

----- #1. For Sunday, January 5, 2003 -----

1 = wkOfYr funtion

2 = Global::weekOfYear method

 

----- #2. For Wednesday, August 20, 2003 -----

34 = wkOfYr funtion

34 = Global::weekOfYear method

 

----- #3. For Sunday, December 28, 2003 -----

52 = wkOfYr funtion

1 = Global::weekOfYear method


Announcements: To see known issues and recent fixes, use Issue search in Microsoft Dynamics Lifecycle Services (LCS).

Community Additions

ADD
Show: