I\'m writing an equipment rental application where clients are charged a fee for renting equipment based on the duration (in days) of the rental. So, basically, (daily fee *
You could adjust the start date to midnight of the same day, then calculate the number of 24-hour periods between the dates. Then, you would take the ceiling or floor of that number depending on whether you want to count any part of a day as a whole day or not.
function dateDiff(startDate, endDate) {
// set startDate to the beginning of the day
startDate = new Date(
startDate.getFullYear(),
startDate.getMonth(),
startDate.getDate());
return Math.floor((endDate - startDate) / 1000*60*60*24);
}