Jump to content

Recommended Posts

 

 

This function

 

       

function SumaHoras( $time1, $time2 )
        {
            list($hour1, $min1, $sec1) = parteHora($time1);
            list($hour2, $min2, $sec2) = parteHora($time2);

            return date('H:i:s', mktime( $hour1 + $hour2, $min1 + $min2, $sec1 + $sec2));
}  

 

echoes returns 05:33

 

when implemented

 

$totaltotal = SumaHoras($currenttime,$secondtime);

 

values $time1 and $time2 are

 

14:32

15:01

 

I want it to return 29:33.... how do I do that ?

 

Thanks in advance

return ($hour1 + $hour2) . ":" . ($min1 + $min2) + ceil(($sec1 + $sec2) / 60);

 

Should work. Untested however.

 

That won't work. The times 12:33 + 10:45 would come out to 22:78. The script needs to account for times where the seconds and/or minutes would add up to more than 60 to add to the next higher increment

 

Tested:

function SumaHoras($time1, $time2)
{
    list($hour1, $min1, $sec1) = explode(':', $time1);
    list($hour2, $min2, $sec2) = explode(':', $time2);

    $secs  = ($sec1 + $sec2) % 60;
    $mins  = ($min1 + $min2 + floor(($sec1+$sec2-$secs)/60)) % 60;
    $hours = ($hour1 + $hour2 + floor(($min1+$min2+floor(($sec1+$sec2-$secs)/60)-$mins)/60));

    return sprintf("%s:%02s:%02s", $hours, $mins, $secs);
}

return ($hour1 + $hour2) . ":" . ($min1 + $min2) + ceil(($sec1 + $sec2) / 60);

 

Should work. Untested however.

 

That won't work. The times 12:33 + 10:45 would come out to 22:78. The script needs to account for times where the seconds and/or minutes would add up to more than 60 to add to the next higher increment

 

Tested:

function SumaHoras($time1, $time2)
{
    list($hour1, $min1, $sec1) = explode(':', $time1);
    list($hour2, $min2, $sec2) = explode(':', $time2);

    $secs  = ($sec1 + $sec2) % 60;
    $mins  = ($min1 + $min2 + floor(($sec1+$sec2-$secs)/60)) % 60;
    $hours = ($hour1 + $hour2 + floor(($min1+$min2+floor(($sec1+$sec2-$secs)/60)-$mins)/60));

    return sprintf("%s:%02s:%02s", $hours, $mins, $secs);
}

 

Nice, yea my mind isn't working today. Thanks for correcting that =)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.