JQuery UI Datpicker seven days a week minDate

How to make jQuery UI datepicker exclude weekends, and also set minDateto a specific value, for example + 2 / + 3 (excluding weekends) ???

What I tried:

$("#txtFromDate").datepicker({
    minDate: 4, 
    beforeShowDay: $.datepicker.noWeekends,
    changeMonth: true,
    changeYear: true
});
<input type="text" id="txtFromDate" />

For example . When I select Monday (for example, today is the 10th) and give 'minDate' as 10, it should be turned on from the 24th year.

Can anyone help me out? I want to calculate the value minDate, not including Saturday and Sunday.

FIDDLE- http://jsfiddle.net/betrob/7DHVr/2/

thanks

+4
source share
2 answers

@Shiva, . , , .:)

DEMO

var count = 10;
//Add the 2 days of weekend in numer of days .
var d = new Date();
count = count + (parseInt(count/5))*2;
d.setDate(d.getDate() +count);
//suppose its ending on weekend day then increment them manually.
if(d.getDay()>5) {  d.setDate(d.getDate()+ (d.getDay()-5)) ; } 

$(document).ready(function () {
   $("#txtFromDate").datepicker(
       { minDate: d, 
                beforeShowDay: $.datepicker.noWeekends,
                changeMonth: true,
                changeYear: true});
 });

: .

+3

minDate, .

// Calculate the next working day manually
    var startDate = new Date(),
    noOfDaysToAdd = 10,
    count = 1;

while(count <= noOfDaysToAdd){
    startDate.setDate(startDate.getDate() + 1);
    if(startDate.getDay() != 0 && startDate.getDay() != 6){
        count++;
    }
}

// Datepicker Init
$('#txtFromDate').datepicker({
    minDate: startDate,
    beforeShowDay: $.datepicker.noWeekends,
    changeMonth: true,
    changeYear: true
});

. DEMO

+4

Source: https://habr.com/ru/post/1526103/


All Articles