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'
}
);
In the calendar widget their is an option to select max date, in which you can set the value as CurrDate(). So that future dates in the calendar would be disabled.
DateRangePicker can be inactivated on a page, by setting enabled value as false that will disable the component completely from all the user interactions including in form post.
To make any past dates disable or for only future dates, you first have to find the instantiation of the datepicker, and set the startDate setting to '+0d'.
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
This worked for me endDate: "today"
$('#datepicker').datepicker({
format: "dd/mm/yyyy",
autoclose: true,
orientation: "top",
endDate: "today"
});
SOURCE
In my case, I have given this attribute to the input tag
data-date-start-date="0d"
data-date-end-date="0d"
You can simply do this
$(function() {
$( "#datepicker" ).datepicker({ maxDate: new Date });
});
JSFiddle
FYI: while checking the documentation, found that it also accepts numeric values too.
Number: A number of days from today. For example 2 represents two days from today and -1 represents yesterday.
so 0
represents today. Therefore you can do this too
$( "#datepicker" ).datepicker({ maxDate: 0 });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With