2 つの日付ピッカー フィールド間の日数を計算して、その値を入力フィールドに表示しようとしています。
日付ピッカーと手動選択の2つの日付間の日数を取得するにはどうすればよいですか?
この作業マニュアルは、次のもののみを選択します。
$(function() {
$("#arrdatepicker").datepicker({
showOn: "button",
buttonImage: "calendar-ico.gif",
buttonImageOnly: true,
onSelect: function(dateText, inst) {
//dateText comes in as MM/DD/YY
var datePieces = dateText.split('/');
var month = datePieces[0];
var day = datePieces[1];
var year = datePieces[2];
//define select option values for
//corresponding element
$('select#arrmonth').val(month);
$('select#arrday').val(day);
$('select#arryear').val(year);
}
});
$("#depdatepicker").datepicker({
showOn: "button",
buttonImage: "calendar-ico.gif",
buttonImageOnly: true,
onSelect: function(dateText, inst) {
//dateText comes in as MM/DD/YY
var datePieces = dateText.split('/');
var month = datePieces[0];
var day = datePieces[1];
var year = datePieces[2];
//define select option values for
//corresponding element
$('select#depmonth').val(month);
$('select#depday').val(day);
$('select#depyear').val(year);
}
});
});
function dateDifference() {
var ev,honap,nap;
var datDate1 = new Date();
var datDate2 = new Date();
var napok;
ev = document.booking.arrivalyear.value;
honap = document.booking.arrivalmonth.value-1;
nap = document.booking.arrivalday.value;
datDate1.setFullYear(ev,honap,nap);
ev = document.booking.departureyear.value;
honap = document.booking.departuremonth.value-1;
nap = document.booking.departureday.value;
datDate2.setFullYear(ev,honap,nap);
napok = Math.floor((datDate2-datDate1)/(24*60*60*1000));
document.getElementById('label').innerHTML=napok+" nights";
}