I have the following array structure in MySQL. There could be no items or many items; the example shows only three.
Array
(
[0] => Array
(
[id] => 1
...
[start_time] => 09:00:00
[finish_time] => 10:20:00
...
)
[1] => Array
(
[id] => 2
...
[start_time] => 13:00:00
[finish_time] => 14:20:00
...
)
[2] => Array
(
[id] => 23
...
[start_time] => 18:05:00
[finish_time] => 19:35:00
...
)
etc etc
)
I want to add the time difference between start_time and finish_time and find out the total time with PHP.
For example, the above should produce 250min or 4 hr 10min (80 min + 80min + 90min). How do I do this?
In PHP:
The strtotime() function will convert the time value to seconds. You can then convert the
$total_diffvalue to minutes, hours, etc as required.If you have access to modify the original MySQL query, you could do it in a single query:
In the above, UNIX_TIMESTAMP performs the same function as strtotime() in PHP.