I would like to set today's date as a maxdate for jQuery datepicker in order to prevent users from picking date greater than today's date
Alex Peattie
$(".datepicker").datepicker({maxDate: '0'});
This will set the maxDate to +0 days from the current date (i.e. today). See:
Smamatti
http://api.jqueryui.com/datepicker/#option-maxDate
$( ".selector" ).datepicker( "option", "maxDate", '+0m +0w' );
If you're using bootstrap 3 date time picker, try this:
$('.selector').datetimepicker({ maxDate: $.now() });
For those who dont want to use datepicker method
var alldatepicker= $("[class$=hasDatepicker]");
alldatepicker.each(function(){
var value=$(this).val();
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10) {
dd='0'+dd
}
if(mm<10) {
mm='0'+mm
}
today = mm+'/'+dd+'/'+yyyy;
if(value!=''){
if(value>today){
alert("Date cannot be greater than current date");
}
}
});
来源:https://stackoverflow.com/questions/7934252/jquery-datepicker-with-today-as-maxdate