Tags

,

WP Datepicker is a simple tool to add date field in any page / post or form. It provides custom JavaScript to fulfill your requirements with weekdays. For example, you can enable one day of week only e.g. first Thursday, disable selected day like Sunday & Monday, disable months e.g. December & January, specific dates and disable specific dates with specific days together.

Custom JavaScript

Here are some customs codes:

  • Need to enable first Thursday Only?
function (date) { 
var day = date.getDay(); 
return [(day == 4) && date.getDate()<8];  
}
  • Need to disable Sunday & Monday?
function (date) { var day = date.getDay(); return [(day != 0 && day != 1)]; }
  • Need to disable the months July and December?
function (date) { 
var month = date.getMonth(); 
return [(month != 6) && (month != 12)]; 
}
  • Need to disable 25th December for specific years?
function (date) { 
var array = ["2020-12-25","2025-12-25","2030-12-25"]; 
var string = jQuery.datepicker.formatDate("yy-mm-dd", date); 
return [ array.indexOf(string) == -1 ]; 
}
  • Need to disable specific days and dates together?
function (date) {

var day = date.getDay();

var array = ["2020-07-04","2020-12-25"]; 

var string = jQuery.datepicker.formatDate("yy-mm-dd", date); 

var sunday = 0;

var monday = 1;

var tuesday = 2;

return [(day != sunday && day != monday && day != tuesday && array.indexOf(string) == -1)];

}