php get day difference between two dates code example
Example 1: date diff php
$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 hours difference between two dates in php
$hourdiff = round((strtotime($time1) - strtotime($time2))/3600, 1);
Example 3: php get day diff
$now = time();
$your_date = strtotime("2010-01-31");
$datediff = $now - $your_date;
echo round($datediff / (60 * 60 * 24));
Example 4: php get date between two dates
$period = new DatePeriod(
new DateTime('2010-10-01'),
new DateInterval('P1D'),
new DateTime('2010-10-05')
);
foreach ($period as $key => $value) {
}
Example 5: 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 ";
?>
Example 6: php check if date between two dates
Current date is between two dates