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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Get start date of week by year and week number.

(0) ShareShare
ReportReport
Posted on by 489

Hi Team,
I want to get first day of the week by given week number and year.

Example: 0523 then it should return 30/01/2023.

I have tried below code, but it is returning 29/01/2023. Please suggest where i am doing wrong.

public static date Week2Date(int year, int week)
    {
        int         yr       = year;
        xSession    xSession = new xSession();
        Date        testDate = DateTimeUtil::getStartOfYearDate(xSession.PreferredLocale(),str2Date(strFmt("%1-01-01", yr), 321));
        Int         weekdays;
        int         wktmp    = (week>1)? (week -1)*7 : 7;
       
        testdate = datetimeutil::date( datetimeutil::addDays(datetimeutil::newDateTime(testdate,0) ,  wktmp));

        if (DateTimeUtil::getWeekOfYear(xSession.PreferredLocale() ,testDate) != week)
        {
            if (week > DateTimeUtil::getWeekOfYear(xSession.PreferredLocale() ,testDate))
            {
                weekdays = 7;
            }
            else
            {
                weekdays = -7;
            }
            while (DateTimeUtil::getWeekOfYear(xSession.PreferredLocale() ,testDate) != week)
            {
                testDate = testDate   weekdays;
            }
        }
        return DateTimeUtil::getStartOfWeekDate(xSession.PreferredLocale() ,testDate);
    }

I have the same question (0)
  • Martin Dráb Profile Picture
    239,985 Most Valuable Professional on at

    Check out In .net, knowing the week number how can I get the weekdays date?, for instance.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 463 Super User 2026 Season 1

#2
Subra Profile Picture

Subra 409

#3
Martin Dráb Profile Picture

Martin Dráb 280 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans