JQuery datepicker from today as maxdate

I want to set the date date as maxdate for jQuery datepicker so that users cannot select a date more than today.

+50
javascript jquery jquery-ui-datepicker
Oct 28 '11 at 19:59
source share
4 answers
$(".datepicker").datepicker({maxDate: '0'}); 

This will set maxDate to +0 days from the current date (i.e. today). Cm:

http://api.jqueryui.com/datepicker/#option-maxDate

+111
Oct 28 '11 at 20:03
source share

http://api.jqueryui.com/datepicker/#option-maxDate

 $( ".selector" ).datepicker( "option", "maxDate", '+0m +0w' ); 
+11
Oct 28 '11 at 20:03
source share

If you are using bootstrap 3 date time picker, try the following:

 $('.selector').datetimepicker({ maxDate: $.now() }); 
+3
Jan 11 '16 at 2:58
source share

For those who do not want to use the 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"); } } }); 
+1
Feb 08 '16 at 9:48
source share



All Articles