25

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. Commented Feb 4, 2013 at 11:35
  • Aren't you getting a syntax error or something? Commented Feb 4, 2013 at 11:57

6 Answers 6

44

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/

Sign up to request clarification or add additional context in comments.

2 Comments

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
@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.
6
$( "#datepicker" ).datepicker( { minDate: 0, maxDate: 365 });
//365 Days

You can use number of days also.

2 Comments

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
here in stackoverflow not for the result which can use directly into project use. Just stackoverflow is using for giving spark and idea... :)
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();

Comments

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));
            }
        }
    });

Comments

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

1 Comment

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.
0
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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.