php - allow datepicker to pick values only upto two weeks from the start date
<script type="text/javascript">
$(function() {
$('#downpayment_date').datepicker({
dateFormat: 'm/d/yy', minDate: new Date(<?php echo $this->y;?>, <?php echo (($this->m) - 1);?>, <?php echo ($this->d);?>),
beforeShowDay: $.datepicker.noWeekends
});
});
</script>
Okay I have this datepicker that allows start date based on the value retrieved dynamically in PHP.
Is it possible to limit the selection of date to just two weeks from the startdate.
.i.e if the start date in the above datepicker starts from 08/12/2012, the datepicker should allow me to only select dates upto two weeks from that date.
$('#downpayment_date').datepicker({
dateFormat: 'm/d/yy', minDate: new Date(<?php echo $this->y;?>, <?php echo (($this->m) - 1);?>, <?php echo ($this->d);?>),
maxDate:new Date(<?php echo $this->y;?>, <?php echo (($this->m) - 1);?>, <?php echo ($this->d)+14;?>),
beforeShowDay: $.datepicker.noWeekends
});
Answer
Solution:
Probably the easiest thing would be to pass in the PHP date and just add 14 days to it like this:
This handles dates across months and years just fine. Here's a jsFiddle example. So instead of hard coding the start date as I do above, just echo the PHP date as you noted.
Answer
Solution:
Use the maxDate attribute in the date picker and set it to minDate + 14
Answer
Solution:
Actually I found the above method bit more efficient and faster.