Add days after date is selected excluding weekends and holidays

前端 未结 3 1930
半阙折子戏
半阙折子戏 2021-01-06 10:28

I have two text fields. In the first textfield I have added a calendar using jQueryUI Datepicker. When the user selects the date from the datepicker, it should automatically

3条回答
  •  失恋的感觉
    2021-01-06 11:02

    Solved it! This answer here helped tremendously.

    Code:

    function AddBusinessDays(weekDaysToAdd) {
          var curdate = new Date();
          var realDaysToAdd = 0;
          while (weekDaysToAdd > 0){
            curdate.setDate(curdate.getDate()+1);
            realDaysToAdd++;
            //check if current day is business day
            if (noWeekendsOrHolidays(curdate)[0]) {
              weekDaysToAdd--;
            }
          }
          return realDaysToAdd;
    
        }
    
    
    var date_billed = $('#datebilled').datepicker('getDate');
    var date_overdue = new Date();
    var weekDays = AddBusinessDays(30);
    date_overdue.setDate(date_billed.getDate() + weekDays);
    date_overdue = $.datepicker.formatDate('mm/dd/yy', date_overdue);
    $('#datepd').val(date_overdue).prop('readonly', true);
    

提交回复
热议问题