22

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
});
2
  • It seems you're assigning 0.004470938897168405 (18 divided by octal 2 divided by 2013) to maxDate instead of a date string. Feb 4, 2013 at 11:35
  • Aren't you getting a syntax error or something?
    – Salman A
    Feb 4, 2013 at 11:57

5 Answers 5

40

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/

2
  • of i remove 'minDate' and use the rest, it will show 1 month ahead. for exact daet i want in 'maxDate' then i have to decrease month with 1. Other than that works great. Thanks
    – Jay Katira
    Dec 2, 2017 at 5:56
  • 3
    @JayKatira: That's because for whatever reason, the month parameter uses a 0-based index whereas day and year are 1-based. This is one of those WHY?!?! moments.
    – Antti29
    Mar 8, 2018 at 8:29
5
$( "#datepicker" ).datepicker( { minDate: 0, maxDate: 365 });
//365 Days

You can use number of days also.

2
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review
    – Niladri
    Aug 1, 2018 at 11:43
  • 1
    here in stackoverflow not for the result which can use directly into project use. Just stackoverflow is using for giving spark and idea... :)
    – Ramesh
    Aug 1, 2018 at 12:23
2

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();
1

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));
            }
        }
    });
1
$(document).ready(function() {
 $( "#dob" ).datepicker({
       maxDate: -0,
      changeMonth:true,
      changeYear:true,
      yearRange:"-100:+100",
      dateFormat: "yy-mm-dd",
    });
});
1
  • 2
    Please don't post only code as an answer, but also include an explanation of your code and how it solves the problem of the question. Answers with an explanation are usually of higher quality, and are more likely to attract upvotes. Mar 21, 2020 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.