我想找到两个日期之间的差异,其中 m 在文本框中给出日期值,我希望将差异/持续时间传递给其他文本框。
<script language=javascript>
function formshowhide(id) {
if (id == "other") {
//document.getElementById('quotef').style.display = "block";
document.getElementById('otherf').style.display = "block";
//here m writng the function for finding duration
var txtdate1 = document.getElementById('MainContent_txtOStartDate').value;
var txtdate2 = document.getElementById('MainContent_txtOEndDate').value;
var date1 = new Date(txtdate1.split('-')[0], txtdate1.split('-')[1] - 1, txtdate1.split('-')[2]);
var date2 = new Date(txtdate2.split('-')[0], txtdate2.split('-')[1] - 1, txtdate2.split('-')[2]);
var timediffsec = date2.getTime() - date1.getTime();
var timediffday = parseInt(timediffsec / (24 * 3600 * 1000));
document.getElementById('MainContent_txtDays').value = timediffday;
//here the function end for finding the duration
}
else {
// document.getElementById('quotef').style.display = "none";
document.getElementById('otherf').style.display = "none";
}
}
</script>