hammerklavier Posted January 16, 2009 Share Posted January 16, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/141123-question-about-addimg-hours-not-in-date-format/ Share on other sites More sharing options...
premiso Posted January 16, 2009 Share Posted January 16, 2009 return ($hour1 + $hour2) . ":" . ($min1 + $min2) + ceil(($sec1 + $sec2) / 60); Should work. Untested however. Quote Link to comment https://forums.phpfreaks.com/topic/141123-question-about-addimg-hours-not-in-date-format/#findComment-738621 Share on other sites More sharing options...
Psycho Posted January 16, 2009 Share Posted January 16, 2009 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); } Quote Link to comment https://forums.phpfreaks.com/topic/141123-question-about-addimg-hours-not-in-date-format/#findComment-738647 Share on other sites More sharing options...
hammerklavier Posted January 16, 2009 Author Share Posted January 16, 2009 worked thanks ... greatly appreciated ! solved ! Quote Link to comment https://forums.phpfreaks.com/topic/141123-question-about-addimg-hours-not-in-date-format/#findComment-738653 Share on other sites More sharing options...
premiso Posted January 16, 2009 Share Posted January 16, 2009 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 =) Quote Link to comment https://forums.phpfreaks.com/topic/141123-question-about-addimg-hours-not-in-date-format/#findComment-738679 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.