jquery datepicker: select date as back as 6 months
- by Abu Hamzah
Start date: user can select start date as back as 6 months. example: if today is 04/23/2010 then i can go back up to 11/23/2009 but not more than 6 months.
<script type="text/javascript">
$(document).ready(function () {
$('#endDate').datepicker({ showOn: 'button',
buttonImage: '../images/Calendar.png',
buttonImageOnly: true, onSelect: function () { },
onClose: function () { $(this).focus(); }
});
$('#startDate').datepicker({ showOn: 'button',
buttonImage: '../images/Calendar.png',
buttonImageOnly: true, onSelect:
function (dateText, inst) {
$('#endDate').datepicker("option", 'minDate', new Date(dateText));
}
,
onClose: function () { $(this).focus(); }
});
});
update code:
var currentDate = new Date();
var currentMonth = currentDate.getMonth() + 1;
var sixMonths = currentMonth + 6
currentDate.setMonth(currentDate.currentMonth, sixMonths);
var myNewCurrentDate = new Date(currentDate)
$('#startDate').datepicker('option', { minDate: myNewCurrentDate });
i am getting currentDate = NaN