Click here to Skip to main content
15,887,368 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have this datepicker with 5 days range interval but i need to disable saturday and sunday for this datepicker im kinda new to js so i might need a help in this one.

<!DOCTYPE html>


	<title>


   
  <div>Please Select Dates:</div>
	 <p>Start Date:</p>
	 <p>End Date:</p>



    $(document).ready(function() {
        var minDate;
        var maxDate;
        var mDate
        var j = jQuery.noConflict();
        j("#startTime").datepicker({

            onSelect: function() {
                minDate = j("#startTime").datepicker("getDate");
                var mDate = new Date(minDate.setDate(minDate.getDate()));
                maxDate = new Date(minDate.setDate(minDate.getDate() + 4));
                j("#endTime").datepicker("setDate", maxDate);
                j("#endTime").datepicker("option", "minDate", mDate);
                j("#endTime").datepicker("option", "maxDate", maxDate);
            }
        });
        var tdate = new Date();
        var ddate = new Date(tdate.setDate(tdate.getDate() + 4));
        j("#startTime").datepicker("setDate", new Date());
        j("#endTime").datepicker();
        j("#endTime").datepicker("setDate", ddate);
    });

What I have tried:

i tried to search it up but i can't achieve the desired output
Posted
Updated 17-Dec-19 20:21pm
v2

hi your problem is pretty simple. just use this following code.
JavaScript
$(function(){

/* suppose you are trying to disable sunday(0 index),and saturday(6 index) */

$('#yourDatePickerId').datepicker({
    daysOfWeekDisabled: [0,6]
});

});
 
Share this answer
 
Hi
You can also use this way

j("#startTime").datepicker({
beforeShowDay: $.datepicker.noWeekends
});

j("#endTime").datepicker({
beforeShowDay: $.datepicker.noWeekends
});
 
Share this answer
 

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