0

I want to disable first saturday of every month + I want to disable all sundays I have tried below code which will only disable every sundays.How can I disable first saturday of every month ?? Below is the code I have tried : $(function () {

        $("#txtDate").datepicker({
            beforeShowDay: noSunday
        });
        function noSunday(date) {
            var day = date.getDay();
            return [(day > 0), ''];
        };
    });

1 Answers1

1

You have done a pretty good work on disabling the Sunday as mentioned in your question. As (day > 0) will enable date except for the Sunday's. Now, for adding the restriction for the first Monday of the month you can use,

var day = date.getDay();
day.getDate(); //Returns the numbering of date. e.g Jan 1 will return 1 , Jan 2 will return 2 and so on.

So if you want to check for First Monday you need to do,

!(day==6 && date.getDate() <= 7)
//Day==6 denotes Saturday

So, The complete code will look like,

function disableDate(date) {
      var day = date.getDay();
      return [ (day!=0 && !(day==6 && date.getDate() <= 7)), ''];
 }

See the demo here.

Runcorn
  • 5,144
  • 5
  • 34
  • 52
  • I want all Saturday's to be disabled,not .MONDAYS. Also I want to show first saturday,rest of saturday should get disabled. – darshan doshi Feb 23 '15 at 02:26
  • So, What seems to be the problem just restructured the equation above to get the desired result. – Runcorn Feb 23 '15 at 03:55
  • Yes i misunderstood the problem and disabled the Monday instead. But it conflict with your comment above : `How can I disable first saturday of every month ??` – Runcorn Feb 23 '15 at 03:56