I have an array with times (string) e.g "2:23", "3:2:22" etc.
$times = array("2:33", "4:2:22", "3:22") //loner
I want to find the total sum of all array.
Is there a way that I could add times like "2:33" and "3:33" ("i:s")
thanks
I have an array with times (string) e.g "2:23", "3:2:22" etc.
$times = array("2:33", "4:2:22", "3:22") //loner
I want to find the total sum of all array.
Is there a way that I could add times like "2:33" and "3:33" ("i:s")
thanks
So you want to add a duration to a time, meaning add a number of hours, minutes and seconds to a time?
Perhaps you might use Dav's strtotime to get the seconds from midnight for the time, then add the duration using an sscanf, thus:
Can't test this from where I am so pls excuse any syntax errors... just trying to give an example. You'll also need to iterate across your array of course.
There is no builtin way of doing this - all time functions operate on times, not on durations. In your case, you can
explode()
and add the parts separately. I would recommend writing a class. Simple example:You might want to look at the PHP date/time functions - one option would be to use something like strtotime():