3

I'm having a hard time setting the max date of the jquery datepicker. I want to add thirty days to the min date.

I get my date in dd.mm.yyyy format. I split the date and make a Date object to use this as mindate (this works). My problem is that I cant use '+30D' on the maxdate property, and I have also tried making a second date object as my maxdate without any effect.

My current code that does not work:

        var values = validdate.split(".");
        var parsed_date = new Date(values[2], values[1], values[0]);

        var maxdate = new Date();
        maxdate.setDate(parsed_date.getDate() + 30);

        $("#date").datepicker({
            changeMonth: true,
            changeYear: true,
            minDate: parsed_date,
            maxDate: maxdate
        });
0

1 Answer 1

7

The problem with maxdate is you are using current date as the start point. Then you add 30 days to today.

To fix use the parsed_date to create the initial maxdate

var maxdate = new Date(parsed_date);
maxdate.setDate(parsed_date.getDate() + 30);

Otherwise you would need to also set month and set year to current date, not just set date

DEMO: http://jsfiddle.net/2y67W/

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

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.