2013-9-26-js计算日期天数差
function daymath(sdate, edate) {
var startdate = sdate;
var enddate = edate;
if (startdate == "" || enddate == "") {
return;
}
startdate = startdate.replace(/-/g, "/");
enddate = enddate.replace(/-/g, "/");
var hour = (new Date(enddate) - new Date(startdate)) / 1000 / 60 / 60 / 24;
var inthour = parseInt(hour);
if (inthour <= 0) {
$("#day").val("");
return;
}
var h = hour.toString();
var hflot = 0;
var day = 0;
if (h.indexOf('.') > 0) {
hflot = parseInt(h.substring(h.indexOf('.') + 1, (h.indexOf('.') + 2)));
}
if (hflot > 5) {
day = inthour + 1;
}
if (hflot > 0 && hflot < 5) {
day = inthour + 0.5;
}
else {
day = inthour;
}
return day;
}