views:

7557

answers:

8

How to calculate minute difference between two date-times in PHP?

+8  A: 

Subtract the past-most one from the future-most one and divide by 60.

Times are done in unix format so they're just a big number showing the number of seconds from January 1 1970 00:00:00 GMT

Oli
+2  A: 

Here is the answer:

print("<?php
$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";
?>");
@user38526 thank's, was the best solution...
Harish Kurup
+2  A: 
<?php
$date1 = time();
sleep(2000);
$date2 = time();
$mins = ($date2 - $date1) / 60;
echo $mins;
?>
Tom
Correction: The last line should be - echo $mins.
Yeti
Thanks, corrected.
Tom
A: 

You are the MAN...thanx, you were most helpful

Please use comments to comment.
Tom
A: 

How would I do this if my "times" are stored as data in cells?

[eg: check-out time minus check-in time = wait time]

Travis
Please use comments to comment.
Tom
A: 

Thanks....this is the best, simple, smart code I have seen so far for this problem of date difference.

coder
A: 

Works like a charm, thnx :)

Lover