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

Ejaz Karim picture Ejaz Karim · Feb 11, 2013 · Viewed 224.3k times · Source

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);
    }

Answer

techfoobar picture techfoobar · Feb 11, 2013

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