How to calculate Number of 'Working days' between two dates in Javascript using moment.js?

前端 未结 7 2033
我寻月下人不归
我寻月下人不归 2020-12-31 05:21

How to calculate the number of working days between two dates in JavaScript using moment.js. I have a working formula that calculate these days, but the formula does not sat

相关标签:
7条回答
  • 2020-12-31 06:08

    you can try this(without loop):

      function getBusinessDays(endDate, startDate) {
        var lastDay = moment(endDate);
        var firstDay = moment(startDate);
        let calcBusinessDays = 1 + (lastDay.diff(firstDay, 'days') * 5 -
          (firstDay.day() - lastDay.day()) * 2) / 7;
    
        if (lastDay.day() == 6) calcBusinessDays--;//SAT
        if (firstDay.day() == 0) calcBusinessDays--;//SUN
    
        return calcBusinessDays;
      }
    

    Original Source

    0 讨论(0)
提交回复
热议问题