1

Can you please show me how to enable range in jquery ui datepicker, I want to determine range in the format: from 2012-12-10 to 2012-12-20 etc (yy-mm-dd, already specified). All other dates should not be available.

Appreciate the help I can get, cheers!

1
  • 1
    Have you looked at the [documentation](api.jqueryui.com/datepicker/), there is even a demo on how to do that. Commented Nov 23, 2012 at 14:14

4 Answers 4

6

try this:

function setInterval(){
$(function() {
    $( "#startDate" ).datepicker({
        defaultDate: "+1w",
        onSelect: function( selectedDate ) {
            $( "#endDate" ).datepicker( "option", "minDate", selectedDate );
        }
    });
    $( "#endDate" ).datepicker({
        defaultDate: "+1w",
        onSelect: function( selectedDate ) {
            $( "#startDate" ).datepicker( "option", "maxDate", selectedDate );
        }
    });
});
}

where

startDate  
endDate

are the two input fields of datepicker

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

Comments

1

Try something like:

jQuery("#date").datepicker({
    beforeShow: function() {
        return {
            dateFormat: 'yy-mm-dd',
            minDate: '2012-12-10',
            maxDate: '2012-12-20',
        }
    }
});

Comments

0

Use maxDate and minDate options when creating.

Link

Code:

$( "#datepicker" ).datepicker({ minDate: value1, maxDate: value2 });

Comments

0

The previous answer is correct, example:

$(function() {
    $( "#datepicker" ).datepicker({ minDate: new Date(2012, 12, 10), maxDate: new Date(2012, 12, 20) });
});

I just wanted to add the following links which you might find useful:

http://jqueryui.com/datepicker/#min-max

http://api.jqueryui.com/datepicker/

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.