get days duration php code example
Example 1: php difference between two dates
$date1 = "2007-03-24";
$date2 = "2009-06-26";
$diff = abs(strtotime($date2) - strtotime($date1));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
printf("%d years, %d months, %d days\n", $years, $months, $days);
Example 2: how to calculate days between two dates in php
<?php
function dateDifference($start_date, $end_date)
{
$diff = strtotime($start_date) - strtotime($end_date);
return ceil(abs($diff / 86400));
}
$start_date = "2016-01-02";
$end_date = "2016-01-21";
$dateDiff = dateDifference($start_date, $end_date);
echo "Difference between two dates: " . $dateDiff . " Days ";
?>