get difference between two dates in days code example
Example 1: How to calculate the difference between two dates
$datetime1 = new DateTime('2020-10-11 16:52:52');
$datetime2 = new DateTime('2020-10-13 16:52:52');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%a days');
Example 2: get days between two dates
function parseDate(str) {
var mdy = str.split('/');
return new Date(mdy[2], mdy[0]-1, mdy[1]);
}
function datediff(first, second) {
return Math.round((second-first)/(1000*60*60*24));
}
alert(datediff(parseDate(first.value), parseDate(second.value)));