0

HI EVERYONE,

I have one problem, as i calculate two time like today i have worked 9.43 hours and 2nd day i worked 8.20 hours when i calculate total time of these two day then it shows 17.63 hours but i want to show this with the help of php , this should come as like 18.03 hours.

How i can do this , please help me.

regards,
Gagan

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by almostbob
0

Just use the following code. Simple and easy to use.

//set the values
$value_a=9.43;
$value_b=8.20;

//now to calculate
$value=$value_a+$value_b;
$valuesplit=explode('.',$value);
if(!isset($valuesplit[1]))
    {
    $endvalue=$valuesplit[0];
    } else {
    if ($valuesplit[1]>=60)
        {
        $valuesplit[1]='0.'.$valuesplit[1];
        $valuesplit[1]=$valuesplit[1]-0.60;
        $valuesplit[0]+=1;
        $valuesplit[1]=preg_replace('/[^.]+[.](.*)/','$1',$valuesplit[1]);
        }
    $endvalue=$valuesplit[0].'.'.$valuesplit[1];
    }

//now to echo the value
echo $endvalue;
0

change the separator to :
strtotime functions think that x.y is a fraction x:y is a time
$a = 9.43 = 9:25
$b = 8.20 = 8:12
= 17.63 = 17:37

You want
$a = 9:43
$b = 8:20
= 18:03
then you can just add the hours with mktime(strtotime($a + $b))

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.