0

I'm using dangrossman daterangepicker. I found a way to disable saturdays and sundays in the picker like this:

isInvalidDate: function(date){
 return (date.day() == 0 || date.day() == 6);}

Then I am computing the number of days like this:

function(start, end, label)
    {
        console.log(label);
        var hd = end.diff(start, 'days');
        $('#totalDays').val(hd);
    });

But it is still including the saturdays and sundays in the computation. Is there a way to exclude it ? thanks!

OneLazy
  • 499
  • 4
  • 16
  • possibly u can found your solution here: http://stackoverflow.com/a/3464346/2651863 – Deepak Sharma Feb 17 '17 at 06:19
  • Looks like daterangepicker uses moment.js. You can adapt this: http://stackoverflow.com/questions/20788411/how-to-exclude-weekends-between-two-dates-using-moment-js – jeff carey Feb 17 '17 at 06:21

1 Answers1

0

For a brute force approach, you can count the days until the end day is reached, and exclude the weekends:

function(start, end, label)
{
    // I don't know if this check is needed, but just to be sure
    if(start.isAfter(end)){
        var swap = start.clone();
        start = end;
        end = swap;
    }
    var counter = start.clone();
    var days = 1;
    while(!counter.isSame(end)){
        if(counter.day() != 0 && counter.day() != 6)
        {
            days++;
        }
        counter.add(1,"days");
    }
    $('#totalDays').val(days);
});
Taha Paksu
  • 15,371
  • 2
  • 44
  • 78