Reputation: 13206
I want to set the maxDate
of jQuery UI to 18/02/2013
but upon trying, it only lets me update it to today's date.
How can I go about doing this?
$("#datepicker'.$row['id'].'").datepicker({
minDate: -0,
dateFormat: \'dd/mm/yy\',
maxDate: 18/02/2013
});
Upvotes: 22
Views: 136967
Reputation: 901
const today = new Date();
const yesterday = new Date(today);
yesterday.setDate(today.getDate() - 1);
In Datepicker
maxDate : yesterday
This worked for me when i using react
Upvotes: 0
Reputation: 11
$(document).ready(function() {
$( "#dob" ).datepicker({
maxDate: -0,
changeMonth:true,
changeYear:true,
yearRange:"-100:+100",
dateFormat: "yy-mm-dd",
});
});
Upvotes: 1
Reputation: 392
I am setting max date using event functions:
$('#datepicker').datepicker({
changeMonth: true,
changeYear: true,
yearRange: "-9:+1",// you can define range of year here.
dateFormat: 'MM yy',
onClose: function () {
var iMonth = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var iYear = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(iYear, iMonth, 1));
},
beforeShow: function () {
var selDate = $(this).val();
if ((selDate.length) > 0) {
iYear = selDate.substring(selDate.length - 4, selDate.length);
iMonth = jQuery.inArray(selDate.substring(0, selDate.length - 5),
$(this).datepicker('option', 'monthNames'));
$(this).datepicker('option', 'defaultDate', new Date(lastYear, iMonth, 1));
$(this).datepicker('option', 'maxDate', new Date(lastYear, 12, 1));
$(this).datepicker('setDate', new Date(lastYear, iMonth, 1));
}
}
});
Upvotes: 1
Reputation: 1959
this worked for me by setting the end date picker range from today to 7 more days.
$endDateCtrl.datepicker("option", "minDate", -0);
$endDateCtrl.datepicker("option", "maxDate", '+7D');
$endDateCtrl.datepicker();
Upvotes: 2
Reputation: 5496
Try this:
$("#datepicker").datepicker({ minDate: -0, maxDate: new Date(2013, 1, 18) });
If you want use hard coded date, use the new Date(2013, 1, 18)
pattern.
If you want to use generic pattern, use "+1D +1M +1Y"
.
Reference link: http://jsfiddle.net/pradkumar_n/wQe8c/
Upvotes: 41
Reputation: 1887
$( "#datepicker" ).datepicker( { minDate: 0, maxDate: 365 });
//365 Days
You can use number of days also.
Upvotes: 5