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

JqueryJquery Ui-Datepicker

Jquery Problem Overview


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

$("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);
    }

Jquery Solutions


Solution 1 - Jquery

You can specify minDate as today by adding minDate: 0 to the options.

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

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

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

Solution 2 - Jquery

You can use the minDate property, like this:

$("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, like this:

minDate: new Date(), // = today

Solution 3 - Jquery

Use this one :

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

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

Solution 4 - Jquery

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

Solution 5 - Jquery

I set starting date using this method, because aforesaid or other codes didn't work for me

$(document).ready(function() {
 $('#dateFrm').datepicker('setStartDate', new Date(yyyy, dd, MM));
 });

Solution 6 - Jquery

can also use:

$("input.DateFrom").datepicker({
    minDate: 'today'
});

Solution 7 - Jquery

Set minDate to current date in jQuery Datepicker :

$("input.DateFrom").datepicker({
    minDate: new Date()
});

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEjaz KarimView Question on Stackoverflow
Solution 1 - JquerytechfoobarView Answer on Stackoverflow
Solution 2 - JqueryRory McCrossanView Answer on Stackoverflow
Solution 3 - JqueryNilsView Answer on Stackoverflow
Solution 4 - JqueryGaneView Answer on Stackoverflow
Solution 5 - Jqueryasifaftab87View Answer on Stackoverflow
Solution 6 - Jqueryfeng smithView Answer on Stackoverflow
Solution 7 - JqueryHasib Kamal ChowdhuryView Answer on Stackoverflow