Search code examples
javascriptjqueryjquery-uidatepicker

Disable future dates after today in Jquery Ui Datepicker


I want to disable all the future dates after today in Jquery Ui Datepicker

Here is the Demo :

Code :

$( "#start_date" ).datepicker(

        { 
            maxDate: '0', 
            beforeShow : function()
            {
                jQuery( this ).datepicker('option','maxDate', jQuery('#end_date').val() );
            },
            altFormat: "dd/mm/yy", 
            dateFormat: 'dd/mm/yy'

        }

);

$( "#end_date" ).datepicker( 

        {
            maxDate: '0', 
            beforeShow : function()
            {
                jQuery( this ).datepicker('option','minDate', jQuery('#start_date').val() );
            } , 
            altFormat: "dd/mm/yy", 
            dateFormat: 'dd/mm/yy'

        }

);

Solution

  • Try this

     $(function() {
      $( "#datepicker" ).datepicker({  maxDate: new Date() });
     });
    

    Or you can achieve this using as below:

    $(function() {
      $( "#datepicker" ).datepicker({  maxDate: 0 });
    });
    

    Reference

    DEMO

    UPDATED ANSWER