10-19-2009, 02:56 AM
I have a number of runtimes strings such as "00:03:54", "00:01:57", etc. What is the best way to work with these in PHP? Specifically I want to do some comparisons to determine which is greater/smaller. Any help would be appreciated. Thanks in advance.
10-19-2009, 11:06 PM
If anyone cares, I resolved this issue by splitting the runtime string into parts and then converting each part to seconds. Here is the code snippet:
$timeparts = explode(':', $runtime);
$seconds = ($timeparts * 60 * 60) + ($timeparts * 60) + $timeparts);
Also, in PHP 5.3 there is a new class called DateInterval that can probably assist in working with such types, but I'm still on PHP 5.2.x and so I never got a chance to try out that class.