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 :
Microsoft Dynamics AX (Archived)

how to calculate how many Saturday && Sunday in a particular date range

(0) ShareShare
ReportReport
Posted on by 327

hi all how we can calculate how many Saturdays && Sundays in particular date range

i am giving  below date range   

From date=09/01/2017(mm-dd-yyyy)

To date=09/30/2017(mm-dd-yyyy)

how we can count total number of Saturdays && Sundays 

Thanks in advance 

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    236,184 Most Valuable Professional on at
    RE: how to calculate how many Saturday && Sunday in a particular date range

    Also note that the days of week repeat every seven days, so you don't have to iterate every single day in the period.

  • Verified answer
    Chaitanya Golla Profile Picture
    17,225 on at
    RE: how to calculate how many Saturday && Sunday in a particular date range

    Hi,

    If you have work calendar setup on your machine then you can use the below code. Alternatively, you can make use of dayOfWk as below.

    Calendar.jpg

    static void WeekDays(Args _args)
    {
        WorkCalendarSched   workCalendarSched;
        counter             workingdays;
        counter             totaldays;
        Counter             weekEndDays;
        CalendarId          primCalendar = "XYZ";
        date                start;
        date                end;
        ;
    
        start = mkDate(1,9,2017);
        end   = mkDate(12,9,2017);
    
        workCalendarSched = new workCalendarSched();
    
        // Work calendar schedule    
        while(start <= end)
        {
            totaldays++;
    
            if(workCalendarSched.isdateopen(primCalendar, start) == true)
            {
                workingdays++;
            }
            start++;
        }
       
        info(strfmt("Total days: : %1",totaldays));
        info(strfmt("Total working days: : %1", workingdays));
        info(strfmt("WeekEnd days: : %1",(totaldays - workingdays)));
        
        // Use of dayOfWk
        while(start <= end)
        {
            if (dayOfWk(start) == 6 || dayOfWk(start) == 7)
                weekEndDays++;
            start++;
        }
    
        info(strfmt("WeekEnd days: : %1",weekEndDays));
    }

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

#1
Guy Terry Profile Picture

Guy Terry 2 Moderator

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans