Tony Vincent Tony Vincent - 3 months ago 6x
jQuery Question

Allow only a cetain day of the month in datepicker

My requirement is a little weird but something I can't do without.
I have a jquery datepicker and the user should be able to select any year, any month, BUT ONLY THE 21st DAY OF THE MONTH . I tried

$( "#t_funin_teate_shikyu_change_dt" ).datepicker({
beforeShowDay: function(date){
var dt = date.getDate();
return [dt == 21, ""];

No luck.. Any help much appreciated


Try this:

        beforeShowDay: function (date) {
        if (date.getDate() == 21 ) {
            return [true, ''];
        return [false, ''];




In case if you do not want to see the dates other than 21 and hardcode it then you can try like this

$(function() {
    $('.date-picker').datepicker( {
        changeMonth: true,
        changeYear: true,
        showButtonPanel: true,
        dateFormat: 'mm/dd/yy',
        onClose: function(dateText, inst) { 
            var day = 21;
            var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
            var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
            $(this).datepicker('setDate', new Date(year, month, day));