Reputation: 15
Below is the check_in and check_out
<input type="text" id="check_in" name="check_in" value="Thursday, 17 Apr, 2014">
<input type="text" id="check_out" name="check_out" value="Friday, 18 Apr, 2014">
This is the date picker i used
$('#check_in').datepicker({
minDate: 0,
maxDate: '1Y',
defaultDate:'+1d',
numberOfMonths:2,
dateFormat:'DD, d M, yy',
onSelect: function(date){
var startDate = $('#check_in').datepicker('getDate');
var date = new Date( Date.parse( startDate ) );
date.setDate( date.getDate() + 1 );
var newDate = date.toDateString();
newDate = new Date( Date.parse( newDate ) );
$('#check_out').datepicker('option','minDate',newDate);
startDate.setDate(startDate.getDate() + 30);
$('#check_out').datepicker('option', 'maxDate', startDate);
}
});
$('#check_out').datepicker({
minDate: '1D',
maxDate: '30D',
defaultDate:'+1d',
numberOfMonths:2,
dateFormat:'DD, d M, yy'
});
Here in the page load when i click check_out datepicker, 'minDate' not starting from 18 april. one's i select 17 april from check_in datepicker its working fine
How i set that minDate based on check_in date when i go direct to check_out datepicker?
Upvotes: 0
Views: 3620
Reputation: 40639
Try this,
var oneD=24*60*60*1000;
t1=new Date($('#check_in').val()).getTime();
t2=new Date().getTime();
var diffDays = Math.round((t1 - t2)/(oneD))+2;
$('#check_out').datepicker({
minDate: diffDays+'D',
maxDate: '30D',
defaultDate:'+1d',
numberOfMonths:2,
dateFormat:'DD, d M, yy'
});
Upvotes: 1