最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Jquery Datepicker ToDate Greater than Or Equal To FromDate - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 5

The 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>
发布评论

评论列表(0)

  1. 暂无评论