Home  • Programming • PHP

Minutes difference between two dates using PHP

Method 1
$start_date = new DateTime('2011-09-01 04:10:58');
$since_start = $start_date->diff(new DateTime('2021-09-11 10:25:00'));

echo $since_start->days.' days total<br>';
echo $since_start->y.' years<br>';
echo $since_start->m.' months<br>';
echo $since_start->d.' days<br>';
echo $since_start->h.' hours<br>';
echo $since_start->i.' minutes<br>';
echo $since_start->s.' seconds<br>';


$minutes = $since_start->days * 24 * 60;
$minutes += $since_start->h * 60;
$minutes += $since_start->i;
echo $minutes.' minutes';

Method 2
$to_time = strtotime("2008-12-13 10:42:00");
$from_time = strtotime("2008-12-13 10:21:00");
echo round(abs($to_time - $from_time) / 60,2). " minute";

Comments 0


Share

Copyright © 2024. Powered by Intellect Software Ltd