PDA

View Full Version : Issue in getting the time difference between two variables



newphpbees
29 Jan 2012, 09:33 PM
I have two textboxes that inputted time, and I want to get the difference between two time.

for example:

$IN = 13:35;
$OUT = 17:35;

$OTHours = ($OUT - $IN);

$OTHours = 4.00;


and it is correct, but I have a scenario like this:

$IN = 21:35;
$OUT = 05:35;

$OTHours = -16.00;

it should be 8.00.

Any help is highly appreciated.

Thank you..

besthost
29 Jan 2012, 11:01 PM
Hi newphpbees,

First convert the time as strtotime(your $IN time) and also strtotime(your $OUT time)

For Exampl :
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";
?>");