Jump to content

[SOLVED] strtotime() - difference between 2 timestamps


cell

Recommended Posts

Hi everybody;

i've been looking for a similar post here, but couldn't find any answer... the thing is simple.
i have 2 dates in "MINUTES:SECONDS:MSECONDS" format, which I read as strings. I conver them to time and substract. The time difference is what I need.
A sample:
[code]

$dif = strtotime($globalCUE['timeIndex'][$z]) - strtotime($globalCUE['timeIndex'][$z-1]);

[/code]

[b]everything is fine if MINUTES <= 60[/b]. but this is a CD CUE sheet and it's likely to get input values like "[b]64:12:00[/b]". in this case the function freaks out and returns nothing. any other idea that comes to your mind? any workaround? I guess it can't be that hard...

thanks!
Off the top of my head, I would convert everything to a single time parameter (either seconds or milliseconds) then subtract and convert back. May not be the most efficient method, but the most straitforward.

$time1Ary = array_reverse(explode(":",$globalCUE['timeIndex'][$z]));
$time2Ary = array_reverse(explode(":",$globalCUE['timeIndex'][$z-1]));
$time1 = $time1Ary[0] + $time1Ary[1]*60 + $time1Ary[2]*3600;
$time2 = $time2Ary[0] + $time2Ary[1]*60 + $time2Ary[2]*3600;
$dif = $time1 - $time2; //Difference in milliseconds

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.