jqueryarraysdatepickerjquerydatetimepicker

How to enable specific days for all month in datepicker


How to show only specific days for all months and year in a jquery datepicker. I want to enable only 2 and 16 days for all months. no restriction for year and months. If it is possible give me solution. http://jsfiddle.net/yXMKC/4245/

Js:

var available_formatted_days_list = ["07-02-2018", "07-16-2018"];
function check_available_date( date ) {
    var formatted_date = '', ret = [true, "", ""];
    if (date instanceof Date) {
        formatted_date = $.datepicker.formatDate( 'mm-dd-yy', date );
    } else {
        formatted_date = '' + date;
    }
    if ( -1 === available_formatted_days_list.indexOf(formatted_date) ) {
        ret[0] = false;
        ret[1] = "date-disabled"; 
        ret[2] = "Date not available"; // put your custom message here
    }
    return ret;
}

$('#date').datepicker({
    dateFormat: 'dd-mm-yy',
    beforeShowDay: check_available_date
});

HTML:

<input type="text" name="date" id="date" readonly="readonly" size="12" />

Solution

  • Here is my solution

    $('#date').datepicker({
        dateFormat: 'dd-mm-yy',
        beforeShowDay: function(d) {
        console.log("in"+d.getDate());
           if (d.getDate() == 2 || d.getDate() == 16) {
             return [true, "" ];
           } else {
              return [false, "" ];
           }
        }
    });