How do I disable past dates on jQuery datepicker? I looked for options but don\'t seem to find anything that indicates the ability to disable past dates.
UPDATE: Th
Try this:
$("#datepicker").datepicker({ minDate: 0 });
Remove the quotes from 0
.
Remove the quotes surrounding 0
and it will work.
Working Code Snippet:
// set minDate to 0 for today's date
$('#datepicker').datepicker({ minDate: 0 });
body {
font-size: 12px; /* just so that it doesn't default to 16px (which is kinda huge) */
}
<!-- load jQuery and jQuery UI -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<!-- load jQuery UI CSS theme -->
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<!-- the datepicker input -->
<input type='text' id='datepicker' placeholder='Select date' />
This works:
$("#datepicker").datepicker({ minDate: +0 });
Use the minDate option to set the minimum possible date. http://jqueryui.com/demos/datepicker/#option-minDate
I used the min attribute: min="' + (new Date()).toISOString().substring(0,10) + '"
Here's my code and it worked.
<input type="date" min="' + (new Date()).toISOString().substring(0,10) + '" id="' + invdateId + '" value="' + d.Invoice.Invoice_Date__c + '"/>
var givenStartDate = $('#startDate').val();
alert('START DATE'+givenStartDate);
var givenEndDate = $('#endDate').val();
alert('END DATE'+givenEndDate);
var date = new Date();
var month = date.getMonth()+1;
var day = date.getDate();
var currentDate = date.getFullYear() + '-' +
(month<10 ? '0' : '') + month + '-' +
(day<10 ? '0' : '') + day;
if(givenStartDate < currentDate || givenEndDate < currentDate)
{
$("#updateButton").attr("disabled","disabled");
}
if(givenStartDate < currentDate && givenEndDate > currentDate)
{
$("#updateButton").attr("enabled","enabled");
}
if(givenStartDate > currentDate || givenEndDate > currentDate) {
$("#updateButton").attr("enabled","enabled");
}
Try this. If any mistake, please correct me :) Thanks all.