Need help with a bit of logic..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tarron
Forum Newbie
Posts: 13
Joined: Thu May 23, 2002 12:09 pm

Need help with a bit of logic..

Post 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?
pistolfire99
Forum Commoner
Posts: 58
Joined: Thu May 23, 2002 3:18 pm

Post 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?
tarron
Forum Newbie
Posts: 13
Joined: Thu May 23, 2002 12:09 pm

Post 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.
MattF
Forum Contributor
Posts: 225
Joined: Sun May 19, 2002 9:58 am
Location: Sussex, UK

Post 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;
?>
Post Reply