i have a requirement in which i need to two date pickers for entering from and To Dates.ToDate Should be greater than or equal to From Date(After selecting fromdate,all previous dates should be disabled in second Datepiker).Also both from date and todate should be from current Year only.How can i do the same using jquery date picker configuration.Current i am creating date pikers like this
$(document).on('click', '#From', function () {
$(this).datepicker({ dateFormat: 'dd/mm/yy', changeMonth: true, yearRange: new Date().getFullYear().toString() + ':' + new Date().getFullYear().toString(), changeYear: false });
});
$(document).on('click', '#To', function () {
$(this).datepicker({ dateFormat: 'dd/mm/yy', changeMonth: true, yearRange: new Date().getFullYear().toString() + ':' + new Date().getFullYear().toString(), changeYear: false });
});
Can anyone help on this
i have a requirement in which i need to two date pickers for entering from and To Dates.ToDate Should be greater than or equal to From Date(After selecting fromdate,all previous dates should be disabled in second Datepiker).Also both from date and todate should be from current Year only.How can i do the same using jquery date picker configuration.Current i am creating date pikers like this
$(document).on('click', '#From', function () {
$(this).datepicker({ dateFormat: 'dd/mm/yy', changeMonth: true, yearRange: new Date().getFullYear().toString() + ':' + new Date().getFullYear().toString(), changeYear: false });
});
$(document).on('click', '#To', function () {
$(this).datepicker({ dateFormat: 'dd/mm/yy', changeMonth: true, yearRange: new Date().getFullYear().toString() + ':' + new Date().getFullYear().toString(), changeYear: false });
});
Can anyone help on this
Share Improve this question asked Jan 21, 2015 at 10:27 vmbvmb 3,04816 gold badges64 silver badges96 bronze badges 2- 2 jqueryui./datepicker/#date-range - this does what you want I believe – 97ldave Commented Jan 21, 2015 at 10:28
- did this work for you? please accept and answer below or answer your own question so others can see how you did it. They may have the same problem. Thanks. – 97ldave Commented Jan 21, 2015 at 16:47
1 Answer
Reset to default 5The way to do this without losing the year restriction is:
<script type="text/javascript">
$(function () {
$("#From").datepicker({
dateFormat: 'dd/mm/yy',
changeMonth: true,
yearRange: new Date().getFullYear().toString() + ':' + new Date().getFullYear().toString(),
onClose: function (selectedDate) {
$("#To").datepicker("option", "minDate", selectedDate);
}
});
$("#To").datepicker({
dateFormat: 'dd/mm/yy',
changeMonth: true,
yearRange: new Date().getFullYear().toString() + ':' + new Date().getFullYear().toString(),
onClose: function (selectedDate) {
$("#From").datepicker("option", "maxDate", selectedDate);
}
});
});
</script>