How can i count all weekdays (Saturday, Sunday .....) in month ?

271 views
Skip to first unread message

Ahmed Amen

unread,
May 31, 2015, 11:09:07 AM5/31/15
to ang...@googlegroups.com
Hi

i need to get count of all weekdays (Saturday, Sunday .....) that i have checked from from that let me select day's will employee work on it - in the month i select like:

month: 06-2015

Saturday: 4 day's
Sunday :  4 day's

ect .......

i have did it by c# as code:

        /// <summary>
        /// Get Count Of Work Day's In The Month
        /// </summary>
        void Get_Count_Month_Days(int month, DayOfWeek dayName)
        {
            int daysOfMonth = DateTime.DaysInMonth(year, month);

            for (int i = 1; i <= daysOfMonth; i++)
            {
                if (new DateTime(year, month, i).DayOfWeek == dayName)
                {
                    listOfDays.Add(new DateTime(year, month, i));
                }
            }
            mustWorkDays = listOfDays.Count;
        }

and loop throw day's as:

            if (Saturday_chk.Checked == true)
            {
                Get_Count_Month_Days(Convert.ToInt32(Month_Name_Combo.Value), DayOfWeek.Saturday);
            }

            if (Sunday_chk.Checked == true)
            {
                Get_Count_Month_Days(Convert.ToInt32(Month_Name_Combo.Value), DayOfWeek.Sunday);
            }

            if (Monday_chk.Checked == true)
            {
                Get_Count_Month_Days(Convert.ToInt32(Month_Name_Combo.Value), DayOfWeek.Monday);
            }

            if (Tuesday_chk.Checked == true)
            {
                Get_Count_Month_Days(Convert.ToInt32(Month_Name_Combo.Value), DayOfWeek.Tuesday);
            }

            if (Wednesday_chk.Checked == true)
            {
                Get_Count_Month_Days(Convert.ToInt32(Month_Name_Combo.Value), DayOfWeek.Wednesday);
            }

            if (Thursday_chk.Checked == true)
            {
                Get_Count_Month_Days(Convert.ToInt32(Month_Name_Combo.Value), DayOfWeek.Thursday);
            }

now i need to it with angularjs but i don't know how to it - so please hope anyone here can help me with sample code for doing that ?

Sander Elias

unread,
May 31, 2015, 12:04:30 PM5/31/15
to ang...@googlegroups.com
Hi Ahmed,

I'm not sure what you mean, something like this: http://plnkr.co/edit/IffcD4Cu2BLevRA8Ghar?p=preview
??

doesn't have anything to do with angular actually ;)

Regards
Sander

Ahmed Amen

unread,
May 31, 2015, 1:35:44 PM5/31/15
to ang...@googlegroups.com
Hi Sander,

Thanks it's close from what i need - but i need here to get the count of day's not get them as 4,5,6,...... - so please how can i do that here 

i try it as and it works:

        $scope.calcdates = function (month, year) {
            var day = 1;
            var start = new Date(Date.UTC(year, month - 1, day, 0, 0, 0)); //cals first day of month
            var end = new Date(Date.UTC(year, month, 0, 0, 0, 0)); //last day of month
            var days = [0, 0, 0, 0, 0, 0, 0]; //start of with 7 empty slots to count the dyas (0=sunday...)
            //var parsed = [] //to show the right dates are proccessed, can be dropped

            //loop over the month
            for (; start <= end; start = new Date(Date.UTC(year, month - 1, ++day, 0, 0, 0))) {
                days[start.getDay()] += 1; //add each day to it slot
                //parsed.push(start); //prove POC
            }

            return {
                days: days
            }
        };

and use it as:

{{calcdates(6,2015)}}

but please how can i make it works only on selected days from checkbox ? (i mean not all days of week) as example:

some employee works on "Saturday"; "Sunday"; "Monday"; "Tuesday"; "Wednesday"; "Thursday" - here i will got all days expect Friday only (6 days per week) - so here i will need count of days that employee will worked on the month without any Friday 

and some employee works on "Saturday"; "Monday"; "Wednesday" - here  (3 days per week) - here i will got count of "Saturday"; "Monday"; "Wednesday" days in the month only without any other days on the week

and ect .....

i hope you got what i mean

thanks a lot ....

Ahmed Amen

unread,
May 31, 2015, 1:39:12 PM5/31/15
to ang...@googlegroups.com
Sorry i mean sum of days in array
Reply all
Reply to author
Forward
0 new messages