Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Unanswered

Get start date of week by year and week number.

(0) ShareShare
ReportReport
Posted on by 8

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);
    }

  • Martin Dráb Profile Picture
    Martin Dráb 230,445 Most Valuable Professional on at
    RE: Get start date of week by year and week number.

    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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,391 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans