Page 1 of 1

Need help with a bit of logic..

Posted: Wed May 29, 2002 12:01 pm
by tarron
I'm need a bit of php code that takes a start time and a finish time, say 7:00 and 9:30, and translates the difference to a decimal number, such as 2.5 in this case.

Any ideas?

Posted: Wed May 29, 2002 1:52 pm
by pistolfire99
Well, lets play around with this idea...
You take 2 time measurements and store them in two different variables. Take the difference. This will be in seconds. Divide that by (60) and you will get the value in minutes.
Now, if your time difference is 9000, when u divide it by (60), you will get 150 and if you further divide it by 60, you will get 2.5. Im not sure if this is what you were asking or did I miss the question?

Posted: Wed May 29, 2002 2:01 pm
by tarron
No, I got that, I'm just having trouble making a line of php code that does it for me =) I could easily write and expression that divided numbers, but I'm not sure how to go about changing hourly time into real numbers.

Posted: Wed May 29, 2002 4:22 pm
by MattF
Try this, I'm not sure about strtotime though......

Code: Select all

<?php
$time1 = strtotime("03:10");
$time2= strtotime("15:20");
$time3 = $date2 - $date1;
$time3 = date("H:i",$time3);
echo $time3;
?>