user1594938
user1594938

Reputation:

How to calculate Date Difference in hours and minutes using PHP?

I have this code and he calculate date diference and it's been good so far but I have problem, I want to subtract high number from lower and show value on negative and this code automatically find which number is higher I don't want that.

$to_time = strtotime("2012-10-25 10:42:00");
$from_time = strtotime("2012-10-26 10:21:00");
echo round(abs($to_time - $from_time) / 60,2). " minute";

Upvotes: 0

Views: 1904

Answers (2)

Viral Shah
Viral Shah

Reputation: 2246

Try this

$to_time = strtotime("2012-10-25 10:42:00");
$from_time = strtotime("2012-10-26 10:21:00");
echo round(($to_time - $from_time)/60,2). " minute";

Upvotes: 0

air4x
air4x

Reputation: 5683

Try

echo round(($to_time - $from_time) / 60,2). " minute";

Upvotes: 1

Related Questions