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

Notifications

Announcements

No record found.

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)
  • Verified answer
    Chaitanya Golla Profile Picture
    17,225 on at

    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));
    }
  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

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

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans