|
Posted by Philip Hallstrom on 07/21/05 02:12
> I'm calculating the amount of time that an electric plant can operate with a
> certain amount of gas, let's say:
>
> A plant can work an hour with 10 galons, How long does it will work with 300
> galons?
>
> hrs = (300 galons / 10 galons) = 30 (I could also have a float here!!!)
>
> Then, I have the time the plant was refilled, let's say 16:42, so I need to
> calculate the next hour the plant needs to be refilled. Like 16:42 hrs + 30
> hrs
>
> How can I sum these two values?
> How can I convert the integer or float value 30 to a hour format?
With absolutely no testing and horrible variable names....
$x = "16:42";
$y = 30;
list($h, $m) = explode(":", $x);
$x1 = $h + $m/60;
$total = $x1 + $y;
$h = floor($total);
$m = floor(($total - $h) * 60);
$newtime = "$h:$m";
Navigation:
[Reply to this message]
|