I have from date and to date here. I want to set my maxDate to 3 months depends on the from date selection. If the user select from date 01-01-2014, #to maxDate should be next 3 months based on the from date, like (01-04-2014).
$(function () {
$("#from").datepicker({
minDate: "dateToday",
changeMonth: true,
dateFormat: 'dd-mm-yy',
onClose: function (selectedDate) {
$("#to").datepicker("option", "minDate", selectedDate);
}
});
$("#to").datepicker({
minDate: "dateToday",
changeMonth: true,
dateFormat: 'dd-mm-yy',
maxDate: selectedDate + "+3M", //I want to set condition like this
onClose: function (selectedDate) {
$("#from").datepicker("option", "maxDate", selectedDate);
}
});
});
give me some suggestion to solve my problem
Fiddle DEMO
$(function () {
$("#from").datepicker({
minDate: "dateToday",
changeMonth: true,
dateFormat: 'dd-mm-yy',
onClose: function (selectedDate, instance) {
if (selectedDate != '') { //added this to fix the issue
$("#to").datepicker("option", "minDate", selectedDate);
var date = $.datepicker.parseDate(instance.settings.dateFormat, selectedDate, instance.settings);
date.setMonth(date.getMonth() + 3);
console.log(selectedDate, date);
$("#to").datepicker("option", "minDate", selectedDate);
$("#to").datepicker("option", "maxDate", date);
}
}
});
$("#to").datepicker({
minDate: "dateToday",
changeMonth: true,
dateFormat: 'dd-mm-yy',
onClose: function (selectedDate) {
$("#from").datepicker("option", "maxDate", selectedDate);
}
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With