How to set minDate to current date in jQuery UI Datepicker?

前端 未结 7 623
渐次进展
渐次进展 2020-12-03 04:26

This is my code and it is not working correctly. I want to set minDate to the current date. How can I do it?

$(\"input.DateFrom\").datepicker({
         


        
相关标签:
7条回答
  • 2020-12-03 04:39

    You can use the minDate property, like this:

    $("input.DateFrom").datepicker({
        changeMonth: true, 
        changeYear: true, 
        dateFormat: 'yy-mm-dd',
        minDate: 0, // 0 days offset = today
        maxDate: 'today',
        onSelect: function(dateText) {
            $sD = new Date(dateText);
            $("input#DateTo").datepicker('option', 'minDate', min);
        }
    });
    

    You can also specify a date, like this:

    minDate: new Date(), // = today
    
    0 讨论(0)
  • 2020-12-03 04:39

    minDate property for current date works on for both -> minDate:"yy-mm-dd" or minDate:0

    0 讨论(0)
  • 2020-12-03 04:39

    can also use:

    $("input.DateFrom").datepicker({
        minDate: 'today'
    });
    
    0 讨论(0)
  • 2020-12-03 04:53

    I set starting date using this method, because aforesaid or other codes didn't work for me

    $(document).ready(function() {
     $('#dateFrm').datepicker('setStartDate', new Date(yyyy, dd, MM));
     });

    0 讨论(0)
  • 2020-12-03 04:55

    Use this one :

     onSelect: function(dateText) {
                     $("input#DateTo").datepicker('option', 'minDate', dateText);
                }
    

    This may be useful : http://jsfiddle.net/injulkarnilesh/xNeTe/

    0 讨论(0)
  • 2020-12-03 04:56

    You can specify minDate as today by adding minDate: 0 to the options.

    $("input.DateFrom").datepicker({
        minDate: 0,
        ...
    });
    

    Demo: http://jsfiddle.net/2CZtV/

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

    0 讨论(0)
提交回复
热议问题