我有两个字段,如开始日期和结束日期。我需要的是,当用户从日期选择器中选择日期时,我必须在另一个文本框中显示日期差异。我做了这么多
我知道,我犯了一些错误。请帮帮我。
Fromdate:
<input type="text" name="travelData[From_date]" id="txtFromDate" value="<?php echo readDate($travelData['From_date']); ?>"onfocus="javascript:NewCssCal('txtFromDate','ddmmyyyy')">
To date:
<input type="text" name="travelData[To_date]" id="txtToDate" value="<?php echo readDate($travelData['To_date']); ?>"onfocus="javascript:NewCssCal('txtToDate','ddmmyyyy')" onblur="calculateTourlength()">
<script type="text/javascript">
function calculateTourlength(){
var FromDate = $('#txtFromDate').val();
var ToDate = $('#txtToDate').val();
var tourLength = parseInt(ToDate) - parseInt(FromDate);
alert(tourLength);
$('#tourLength').val(tourLength);
return false;
}
答案 0 :(得分:0)
var startdate = $('#txtFromDate').datepicker('getDate');
var enddate = $('#txtToDate').datepicker('getDate');
var calculate = (enddate - startdate)/1000/60/60/24;
NOTE: Be careful that end date must contain greater value