Rose Rose - 3 months ago 6
jQuery Question

Display a datepicker with dates lies between two given dates in jquery

I have a

start date = '02/08/2016'
,
end date = '20/08/2016'
. Now I need a result in
datepicker
such that, dates from
02/08/2016
to
20/08/2016


should be displayed and all other past and later dates should be disabled.

How can I achieve it?

Answer

this how you can achieve the dates between two dates. hope this may help you, as said by @cfs on this page, you can disable previous days by this script:

$(function() {
    $( "#datepicker,#datepicker1" ).datepicker({
        minDate:new Date()
    });
});


var start = $("#from").datepicker("getDate"),
    end = $("#to").datepicker("getDate"),
    currentDate = new Date(start.getTime()),
    between = []
;

while (currentDate <= end) {
    between.push(new Date(currentDate));
    currentDate.setDate(currentDate.getDate() + 1);
}

here's the fiddle to see working demo

Comments