0

Is there any method in fullcalendar to count active days (the days without holidays and weekend(sunday)) in a month?

for example:

In January we have 31 days, 3 weekends and 5 holidays, so the active days is 23 days (31-(3+5)), how can i count that active day.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Ariona Rian
  • 9,153
  • 3
  • 24
  • 36
  • 1
    How would your code know what days are holidays? (Also, I think you'll find January has a minimum of _four_ weekends, and sometimes five.) – nnnnnn Aug 26 '12 at 04:59
  • from the events we created before or from Local Holidays event – Ariona Rian Aug 26 '12 at 05:02
  • http://stackoverflow.com/questions/9646589/calculate-business-days-between-two-days-should-exclude-holidays – Tats_innit Aug 26 '12 at 05:03
  • Well the formula you want is `(number of days in month) - (number of Saturdays + number of Sundays + number of weekday holidays)`. Your `31-(3+5)` doesn't really make sense because even assming there are three weekends you'd need `31 - (3*2 + 5)` given that weekends are two days long. – nnnnnn Aug 26 '12 at 05:04
  • @nnnnnn yep, that's the formula. but i didn't found a method to check whether the date is weekends (sunday/saturday) or not. – Ariona Rian Aug 26 '12 at 05:08
  • There a JS `Date` method [`.getDay()`](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date/getDay) that returns the day of the week for a specified `Date`. (Well, it returns `0` for Sunday, `1` for Monday and so forth.) – nnnnnn Aug 26 '12 at 07:24
  • finally i got my function work. here is my function : function getActiveDays(bulan,tahun){ var daysinmonth=Date.getDaysInMonth(tahun,bulan); var sundays=0; for(i=1;i<=daysinmonth;i++){ var dayname = new Date(tahun,bulan,i).getDayName(); if(dayname=="Sunday") { sundays++; }; } activedays=daysinmonth-sundays; return activedays; } – Ariona Rian Aug 26 '12 at 07:49

1 Answers1

0

Actually this not related to fullcalendar but I think this script will help you for getting bussiness/Active days (excluding weekends) from given month and year.

function getActiveDays(month,year){
    var daysinmonth=Date.getDaysInMonth(year,month);
    var sundays=0;
    for(i=1;i<=daysinmonth;i++){
        var dayname = new Date(year,month,i).getDayName();
        if(dayname=="Sunday") {
            sundays++;
        };
    }
    activedays=daysinmonth-sundays;
    return activedays;
}

the function above will eliminate sundays from days of the month. for example : getActiveDays(7,2012) will return 27 active days (from august, 2012).

This function use date.js library

Ariona Rian
  • 9,153
  • 3
  • 24
  • 36