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 :
Dynamics 365 Community / Blogs / Simple AX / X++ create date starting fr...

X++ create date starting from year and week number

Daniele Ferraretto Profile Picture Daniele Ferraretto

Elaborating materials present in other parts, below a short piece of code for create a first date of week starting from the number of year and the number of week.

public static date Week2Date(int yr, int week)
{

    Date    testDate = dateStartYr(mkDate(01, 01, yr));
    Int     weekdays;
    int     wktmp = (week>1)? (week -1)*7 : 7;

    testdate = datetimeutil::date( datetimeutil::addDays(datetimeutil::newDateTime(testdate,0) ,  wktmp));

    //info(int2str(weekOfYear(testDate)));
    if (weekOfYear(testDate) != week)
    {
        if (week > weekOfYear(testDate))
        {
           weekdays = 7;
        }
        else
        {
            weekdays = -7;
        }
        while (weekOfYear(testDate) != week)
        {
            testDate = testDate + weekdays;
        }
    }
    return (dateStartWk(testDate));
}



This was originally posted here.

Comments

*This post is locked for comments