Mdc concepts Mdc concepts - 6 months ago 19
jQuery Question

How to set minDate 2

I want to highlight date day after tomorrow date,I am using following code but not working fine.



$('#date').datetimepicker({
timepicker: false,
format: 'Y-m-d',
formatDate: 'Y-m-d',
minDate: 2,
scrollDay: false,
scrollMonth: false,
scrollYear: false
});




Answer

Set the minDate value as a Date object

var date = new Date(); // get current date
date.setDate(date.getDate() + 2); // add two days to it
$('#date').datetimepicker({
  timepicker: false,
  format: 'Y-m-d',
  formatDate: 'Y-m-d',
  minDate: date,
  scrollDay: false,
  scrollMonth: false,
  scrollYear: false
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.4/build/jquery.datetimepicker.full.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.4/jquery.datetimepicker.css" rel="stylesheet" />
<input id="date" />

Or as in the documentation set '+1970/01/03' for min date to day after tomorrow

$('#date').datetimepicker({
  timepicker: false,
  format: 'Y-m-d',
  formatDate: 'Y-m-d',
  minDate: '+1970/01/03',
  scrollDay: false,
  scrollMonth: false,
  scrollYear: false
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.4/build/jquery.datetimepicker.full.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery-datetimepicker/2.5.4/jquery.datetimepicker.css" rel="stylesheet" />
<input id="date" />