Click here to Skip to main content
14,364,335 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have used datepicker jquery ui. I want to disable thursday and Saturday for that particular week after 4pm of monday.

Suppose today's date is 04-11-2019(Monday) then 4pm of monday Thursday (7-11-2019) and Saturday(9-11-2019) should be disable. Next week of thursday and Saturday should be enable.

Can someone please let me know how can I do that?

What I have tried:

$( function() {
    
    //Create array for next 7 days
    var day1 = parseInt(moment().add('days', 1).format('DDMMYYYY'));
    var day2 = parseInt(moment().add('days', 2).format('DDMMYYYY'));
    var day3 = parseInt(moment().add('days', 3).format('DDMMYYYY'));
    var day4 = parseInt(moment().add('days', 4).format('DDMMYYYY'));
    var day5 = parseInt(moment().add('days', 5).format('DDMMYYYY'));
    var day6 = parseInt(moment().add('days', 6).format('DDMMYYYY'));
    var day7 = parseInt(moment().add('days', 7).format('DDMMYYYY'));
    var next7Days = [day1, day2, day3, day4, day5, day6, day7];
 
    var dayOfWeek = moment().format('dddd');
    
    var dateToday = new Date();
    
    console.log(dayOfWeek);

    
    if(dayOfWeek == 'Sunday'){
      var datesToDisable = 3;
    }else if(dayOfWeek == 'Monday'){
      var datesToDisable = 3;
    }else if(dayOfWeek == 'Tuesday'){
      var datesToDisable = 3;
    }else if(dayOfWeek == 'Wednesday'){
      var datesToDisable = 3;
    }else if(dayOfWeek == 'Thursday'){
      var datesToDisable = 3;      
    }else if (dayOfWeek == 'Friday'){
      var datesToDisable = 3;
    }else if(dayOfWeek == 'Saturday'){
      var datesToDisable = 3;
    }
    

    
    if (dayOfWeek == 'Monday' && dateToday.getHours()>=16) {
    	var isWedAfternoon = true;
        var disablesat = true;
    }else{
    	var isWedAfternoon = false;
        var disablesat = false;
    }
    
    
    if (dayOfWeek == 'Monday' && dateToday.getHours()>=16) {
    	var isMondayAfternoon = true;
        var disablethu = true;
    }else{
    	var isMondayAfternoon = false;
        var disablethu = false;
    }
    
      $( "#datepicker" ).datepicker({
        numberOfMonths: 1,
        showButtonPanel: true,
        minDate: datesToDisable,
        maxDate: 18,
        dateFormat: 'ddmmyyyy',
		showOtherMonths: true,
     	selectOtherMonths: true,
        //defaultDate:+7,
        beforeShowDay: function(date) {
          var day = date.getDay();
          

          
          if (disablesat) {
              var daysToDisable = (day != 0 && day != 1 && day != 2 && day != 3 && day != 5 && day != 6);
          }else if(disablethu){
          	  var daysToDisable = (day != 0 && day != 1 && day != 2 && day != 3 && day != 4 && day != 5);
          }else{
          	  var daysToDisable = (day != 0 && day != 1 && day != 2 && day != 3 && day != 5);
          }

			console.log(daysToDisable);
          return [daysToDisable];
          
         
        },
         onSelect: function(_date) {
           var myDate = $(this).datepicker('getDate'); // Retrieve selected date
           var reformattedDate = $.datepicker.formatDate('dd/mm/yy', myDate);
           var dateNumber = parseInt($.datepicker.formatDate('ddmmyy', myDate));
			var dayOfWeek = $.datepicker.formatDate("DD", myDate);
           
           $('#attributeDay').val(dayOfWeek);
           $('#attributeDate').val(reformattedDate);
           
           
           
           if (jQuery.inArray(dateNumber, next7Days)!='-1') {
             $('#dateCheck').html('is in next 7 days');
             $('#attributeFutureDeliver').val('false');
           } else {
             $('#attributeFutureDeliver').val('true');
             $('#dateCheck').html('is NOT in next 7 days')
           }
        }

      });
   
  
    $('.checkout_btn').click(function() {
      if ($('#attributeDate').val() == '') {
        alert("Please pick a delivery date"); 
        return false;
      }
      else {
        $(this).submit();
      }
    });
    
  } );
Posted
Updated 5-Nov-19 4:04am
v2

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100