-1

I am trying to solve this problem. Still I have done this,

$(function() {
    $( "#datepicker" ).datepicker({ 
        dateFormat: 'yy-mm-dd', 
        firstDay: 1,
        minDate:1 
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<input type="text" id="datepicker">

If you run this code you can see the calendar.

I want to disable the full current week. The available dates will start from next week. As, Example, today is 18.07.2016. So, if someone want to use this calendar then this full week become inactive. Next available date will start from 24.07.2016.

Thanks in advance for help.

Mohammad
  • 21,175
  • 15
  • 55
  • 84
Avishake
  • 460
  • 1
  • 6
  • 20
  • By *current week* you mean calendar week right? Not just 7 days – Liam Jul 18 '16 at 09:32
  • 1
    Yes. only the calendar week. Sunday to Saturday. – Avishake Jul 18 '16 at 09:34
  • Have a look at this post, might help you. http://stackoverflow.com/questions/2968414/disable-specific-days-of-the-week-on-jquery-ui-datepicker – Daniel O Mensah Jul 18 '16 at 09:36
  • Yes. I have seen. But this post is for only want to disable specific week day or days of every week. But I don't want that. I want to disable only the current week. Only current Sunday to Saturday. – Avishake Jul 18 '16 at 09:38
  • Read the the comment please. I have written Sunday to Saturday not Sunday n Saturday. – Avishake Jul 18 '16 at 09:41

3 Answers3

2

First find the number of day of week. And mindate will be counted accordingly and all the dates of current week will be disabled. Please refer below code.

$(function() {
    var date = new Date();
    var dayNo = date.getDay();
    var mindate = (7-dayNo);

    $( "#datepicker" ).datepicker({
         dateFormat: 'yy-mm-dd', firstDay: 1,minDate: mindate
    });
});
Rahul Patel
  • 5,248
  • 2
  • 14
  • 26
0

Disabling the current week from Sunday to Saturday, you just need to set the firstDay as 0 (for Sunday) and use beforeShowDay which is used to take date as a parameter and return an array. For reference read Datepicker Option - beforeShowDay

Please check the snippet to enable all other dates in past and future both except disabling the current week dates.

Disable from Sunday to Saturday, use the below snippet

$(function() {
    $("#datepicker").datepicker({
        firstDay: 0,
        beforeShowDay: function (date) {
            var sunday = new Date();
            sunday.setHours(0,0,0,0);
            
            sunday.setDate(sunday.getDate() - (sunday.getDay() || 0));
            var saturday = new Date(sunday.getTime());
            
            saturday.setDate(sunday.getDate() + 6);
            
            if (date >= sunday && date <= saturday) {
              return [false, ''];
            }
            else {
              return [true, ''];
            }
        }
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

<input type="text" id="datepicker">

And, also possibility to disable the whole week starting from Monday to Sunday

$(function() {
    $('#datepicker').datepicker({
        firstDay: 1,
        beforeShowDay: function (date) {
           var monday = new Date();
           monday.setHours(0,0,0,0);

           monday.setDate(monday.getDate() + 1 - (monday.getDay() || 7));
           var sunday = new Date(monday);
           sunday.setDate(monday.getDate() + 6);

           if (date >= monday && date <= sunday) {
              return [false, ''];
           } else {
               return [true, ''];
          }
        }
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

<input type="text" id="datepicker">
Adeel
  • 2,901
  • 7
  • 24
  • 34
0

Its A Simple Way TO Disable a Perticular Week

<script>
 $(function(){
$('.bet_end').datepicker({              //ere .bet_end Is A Datepicker Class Name
    daysOfWeekDisabled: [0,6]   //Here Type Only Column Number To Disable Week 
     });
}); 
</script>

Click here To See Image (Sunday And Saturdat All Week Are Disable)

Paresh Shiyal
  • 534
  • 4
  • 15