Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am working with two date pickers in my from ,To select From date and Two date and set the plan. Once the plan is saved for a particular days. The next time when user want to make new plan i want to disable those dates which are already assigned for previous plan. Dates which i want to disable comes dynamically from the database. I doing coding in Asp.net.


My Question is , Can i disable the dates in jQuery date picker dynamically. if yes, Please advise me the way to do it with an example.

Thanks in Advance.
Posted
Comments
Dhyanga 17-Dec-20 13:07pm    
I am running into same issue. Did you have a solution now?

1 solution

You Can use
beforeshowday
option of JQuery.

Please see the following code to disable Non Working Days.

$(document).ready(function(){

$("#datepicker").datepicker({
beforeShowDay: nonWorkingDates,
numberOfMonths: 1,
minDate: '05/01/09',
maxDate: '+2M',
firstDay: 1
});

function nonWorkingDates(date){
var day = date.getDay(), Sunday = 0, Monday = 1, Tuesday = 2, Wednesday = 3, Thursday = 4, Friday = 5, Saturday = 6;
var closedDates = [[7, 29, 2009], [8, 25, 2010]];
var closedDays = [[Monday], [Tuesday]];
for (var i = 0; i < closedDays.length; i++) {
if (day == closedDays[i][0]) {
return [false];
}

}

for (i = 0; i < closedDates.length; i++) {
if (date.getMonth() == closedDates[i][0] - 1 &&
date.getDate() == closedDates[i][1] &&
date.getFullYear() == closedDates[i][2]) {
return [false];
}
}

return [true];
}

});


Please refer to the link below...

http://stackoverflow.com/questions/501943/can-the-jquery-ui-datepicker-be-made-to-disable-saturdays-and-sundays-and-holid[^]

Please mark it as solution, if this solves your issue.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900