methuselah
methuselah

Reputation: 13206

Set maxDate on jquery ui datepicker to certain date

I want to set the maxDate of jQuery UI to 18/02/2013 but upon trying, it only lets me update it to today's date.

How can I go about doing this?

$("#datepicker'.$row['id'].'").datepicker({
    minDate: -0, 
    dateFormat: \'dd/mm/yy\',
    maxDate: 18/02/2013
});

Upvotes: 22

Views: 136967

Answers (6)

Syamlal
Syamlal

Reputation: 901

const today = new Date();
const yesterday = new Date(today);
yesterday.setDate(today.getDate() - 1);

In Datepicker

maxDate : yesterday

This worked for me when i using react

Upvotes: 0

user13098303
user13098303

Reputation: 11

$(document).ready(function() {
 $( "#dob" ).datepicker({
       maxDate: -0,
      changeMonth:true,
      changeYear:true,
      yearRange:"-100:+100",
      dateFormat: "yy-mm-dd",
    });
});

Upvotes: 1

Sameer
Sameer

Reputation: 392

I am setting max date using event functions:

    $('#datepicker').datepicker({
        changeMonth: true,
        changeYear: true,
        yearRange: "-9:+1",// you can define range of year here.
        dateFormat: 'MM yy',
        onClose: function () {

            var iMonth = $("#ui-datepicker-div .ui-datepicker-month :selected").val();

            var iYear = $("#ui-datepicker-div .ui-datepicker-year :selected").val();

            $(this).datepicker('setDate', new Date(iYear, iMonth, 1));

        },
        beforeShow: function () {
            var selDate = $(this).val();
            if ((selDate.length) > 0) {
                iYear = selDate.substring(selDate.length - 4, selDate.length);
                iMonth = jQuery.inArray(selDate.substring(0, selDate.length - 5),

                $(this).datepicker('option', 'monthNames'));
                $(this).datepicker('option', 'defaultDate', new Date(lastYear, iMonth, 1));
                $(this).datepicker('option', 'maxDate', new Date(lastYear, 12, 1));
                $(this).datepicker('setDate', new Date(lastYear, iMonth, 1));
            }
        }
    });

Upvotes: 1

Jaydeep Shil
Jaydeep Shil

Reputation: 1959

this worked for me by setting the end date picker range from today to 7 more days.

$endDateCtrl.datepicker("option", "minDate", -0);
$endDateCtrl.datepicker("option", "maxDate", '+7D');
$endDateCtrl.datepicker();

Upvotes: 2

NPKR
NPKR

Reputation: 5496

Try this:

$("#datepicker").datepicker({ minDate: -0, maxDate: new Date(2013, 1, 18) });

If you want use hard coded date, use the new Date(2013, 1, 18) pattern.

If you want to use generic pattern, use "+1D +1M +1Y".

Reference link: http://jsfiddle.net/pradkumar_n/wQe8c/

Upvotes: 41

Ramesh
Ramesh

Reputation: 1887

$( "#datepicker" ).datepicker( { minDate: 0, maxDate: 365 });
//365 Days

You can use number of days also.

Upvotes: 5

Related Questions