Got this working on php 5.3
$datetime1 = new DateTime("2011-10-10 10:00:00");
$datetime2 = new DateTime("2011-10-10 10:45:00");
$interval = $datetime1->diff($datetime2);
$hours = $interval->format('%h');
$minutes = $interval->format('%i');
echo 'Diff. in minutes is: '.($hours * 60 + $minutes);
How can i make it work on php 5.2 ? are there any equivalent functions available??
Got it working
$date1 = "2011-10-10 10:00:00";
$date2 = "2011-10-10 10:11:00";
echo round((strtotime($date2) - strtotime($date1)) /60);
To get the number of minutes between 2 dates: Get the number of milliseconds between the unix epoch and the Dates. Subtract the milliseconds of the start date from the milliseconds of the end date. Divide the result by the number of milliseconds in a minute - 60 * 1000 .
=TEXT(TODAY()-D5,"[mm]") Here, the TODAY()-D5 part of the formula returns the difference between the today and the date in D5 in days. The TEXT Function converts this difference to minutes. Press ENTER and you will see the time difference between today and the date in cell D5 by minute.
Instead of DateTime
you can use strtotime
and date
:
$datetime1 = strtotime("2011-10-10 10:00:00");
$datetime2 = strtotime("2011-10-10 10:45:00");
$interval = abs($datetime2 - $datetime1);
$minutes = round($interval / 60);
echo 'Diff. in minutes is: '.$minutes;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With