exclude weekends in javascript date calculation

前端 未结 4 581
甜味超标
甜味超标 2020-11-28 16:22

I have two sets of codes that work. Needed help combining them into one.

This code gets me the difference between two dates. works perfectly:

functio         


        
4条回答
  •  生来不讨喜
    2020-11-28 17:14

    First Get the Number of Days in a month

         totalDays(month, year) {
            return new Date(year, month, 0).getDate();
         }
    

    Then Get No Of Working Days In A Month By removing Saturday and Sunday

      totalWorkdays() {
         var d = new Date(); // to know present date
         var m = d.getMonth() + 1; // to know present month
         var y = d.getFullYear(); // to knoow present year
         var td = this.totalDays(m, y);// to get no of days in a month
         for (var i = 1; i <= td; i++) {  
            var s = new Date(y, m - 1, i);
            if (s.getDay() != 0 && s.getDay() != 6) {
               this.workDays.push(s.getDate());// working days
            }else {
               this.totalWeekDays.push(s.getDate());//week days
             }
          }
          this.totalWorkingDays = this.workDays.length;
     }
    

提交回复
热议问题