Hassan Sardar Hassan Sardar - 7 months ago 40
Javascript Question

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'

}

);

Answer

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

Comments