$('[data-toggle="datepicker"]').datepicker({ format: 'yyyy-mm-dd', autoHide: true, autoPick: true });
function updateStayLength(thisElement) {
if ($(thisElement).attr("id") === "check-in-date") { updateCheckoutToPlusOne($(thisElement).val()); }
var dateString1 = $("#check-in-date").val(); var date1 = new Date(dateString1);
var dateString2 = $("#check-out-date").val(); var date2 = new Date(dateString2);
var difference = daysBetween(date1, date2); if ( difference < 1 ) difference = 1; $("#stay-length").val(difference); } function updateCheckoutToPlusOne(checkInDateString) { var checkInDate = new Date(checkInDateString); var checkOutDate = new Date(checkInDateString); checkOutDate.setDate(checkInDate.getDate() + 1); var dd = checkOutDate.getDate(); var mm = checkOutDate.getMonth() + 1; var yyyy = checkOutDate.getFullYear(); if ( dd < 10 ) dd = '0' + dd; if ( mm < 10 ) mm = '0' + mm; $("#check-out-date").val(yyyy + '-' + mm + '-' + dd); } function daysBetween( date1, date2 ) { var one_day=1000*60*60*24; var date1_ms = date1.getTime(); var date2_ms = date2.getTime(); var difference_ms = date2_ms - date1_ms; return Math.round(difference_ms/one_day); }