How to set minDate to current date in jQuery UI Datepicker?

This is my code and it is not working properly. I want to set minDate to the current date. How can i do this?

 $("input.DateFrom").datepicker({ changeMonth: true, changeYear: true, dateFormat: 'yy-mm-dd', maxDate: 'today', onSelect: function(dateText) { $sD = new Date(dateText); $("input#DateTo").datepicker('option', 'minDate', min); } 
+45
jquery jquery-ui-datepicker
Feb 11 '13 at
source share
7 answers

You can specify minDate as it is today by adding minDate: 0 to the parameters.

 $("input.DateFrom").datepicker({ minDate: 0, ... }); 

Demo : http://jsfiddle.net/2CZtV/

Docs : http://jqueryui.com/datepicker/#min-max

+107
Feb 11 '13 at
source share
โ€” -

You can use the minDate property, for example:

 $("input.DateFrom").datepicker({ changeMonth: true, changeYear: true, dateFormat: 'yy-mm-dd', minDate: 0, // 0 days offset = today maxDate: 'today', onSelect: function(dateText) { $sD = new Date(dateText); $("input#DateTo").datepicker('option', 'minDate', min); } }); 

You can also specify a date, for example:

 minDate: new Date(), // = today 
+15
Feb 11 '13 at
source share

Use this:

  onSelect: function(dateText) { $("input#DateTo").datepicker('option', 'minDate', dateText); } 

This may be useful: http://jsfiddle.net/injulkarnilesh/xNeTe/

+5
Feb 11 '13 at
source share

the minDate property for the current date works for both -> minDate: "yy-mm-dd" or minDate: 0

+4
Oct 10 '13 at 13:20
source share

can also be used:

 $("input.DateFrom").datepicker({ minDate: 'today' }); 
+2
Mar 03 '16 at 8:08
source share

I set the start date using this method because the above or other codes did not work for me

 $(document).ready(function() { $('#dateFrm').datepicker('setStartDate', new Date(yyyy, dd, MM)); }); 
+1
Jun 07 '17 at 4:20
source share
 $("input.DateFrom").datepicker({ minDate: new Date() }); 
0
Dec 28 '17 at 10:51
source share



All Articles