I have looked everywhere for a simple answer to this but I have not been able to find a solution that either works or meets my requirements.
I am looping through data, that looks similar to this:
Array
(
[0] => 4c36fd909b37208b
[1] => event:
[2] => start_scan
[3] => 2012-08-17 12:01:15
)
Array
(
[0] => 4c36fd909b37208b
[1] => sysaction:
[2] => lower_device
[3] => 2012-08-17 12:01:19
)
Array
(
[0] => 4c36fd909b37208b
[1] => event:
[2] => how_to_use_displayed
[3] => 2012-08-17 12:01:46
)
Array
(
[0] => 4c36fd909b37208b
[1] => event:
[2] => scan_displayed
[3] => 2012-08-17 12:01:59
)
Array
(
[0] => 4c36fd909b37208b
[1] => sysaction:
[2] => layer_1_display_on_recognition
[3] => 2012-08-17 12:02:23
)
I want to work out the time between two dates and the result needs to be in the format HH:MM:SS. In the example data above, I need the difference between 2012-08-17 12:01:15 and 2012-08-17 12:02:23, which should be 00:01:08.
I have tried to use the code from here: http://www.if-not-true-then-false.com/2010/php-calculate-real-differences-between-two-dates-or-timestamps/ but it keeps returning 00:00:20
I have also tried this (where the date in the first array is saved as $xpTime and the date in the last array is set to $xpEndTimeTmp):
$start = new DateTime($xpTime);
$end = new DateTime($xpEndTimeTmp);
$diff = $start->diff($end);
$xpDuration = date('H:i:s', strtotime($diff->h.':'.$diff->i.':'.$diff->s));
But that seems to be working either (it returns the same hour, minute and a different second).
I hope someone can help me, tell me what I am doing wrong, or has sample code that could that could set me on the right track!