Try this:
function index()
{
$in = '19:30';
$secs_in = strtotime( $in );
$times = array
(
'19:30',
'19:31',
'23:35',
'01:35',
'03:35',
'05:35',
'07:35',
'19:29',
);
echo "
<!doctype html>
<head>
<title>Time difference</title>
<style type='text/css'>
body {text-align:center; font-size:14px; line-height:1.8em}
table {background-color:#cfc; margin:2em auto}
th {width:10em}
</style>
</head>
<body>
";
echo "<table>
<tr style='font-weight:700; color:#f00'>
<th> time in </th>
<th> time out </th>
<th> secs_in </th>
<th> secs_out </th>
<th> secs_diff </th>
<th> mins_diff </th>
<th> hour:min </th>
</tr>
";
foreach ( $times as $out ):
# maybe $out time is less than $in time
$secs_out = strtotime( $out ); //echo '<br />$out ---> ' .$out .' == ' .$secs_out .' seconds';
if ( $secs_out < $secs_in )
{
$secs_out = 24 * 60 * 60 + $secs_out; // add full day of seconds to time in
}
$secs_diff = $secs_out - $secs_in;
$mins_diff = sprintf('%d', $secs_diff / 60);
$duration = sprintf('%02d:%02d', $mins_diff/60, $mins_diff % 60);
echo '<tr>';
echo '<td>' .$in .'</td>';
echo '<td>' .$out .'</td>';
echo '<td>' .number_format($secs_in) .'</td>';
echo '<td>' .number_format($secs_out) .'</td>';
echo '<td>' .number_format($secs_diff) .'</td>';
echo '<td>' .$mins_diff .'</td>';
echo '<td>' .$duration .'</td>';
echo '</tr>';
endforeach;
echo '</table><body></html>';
die;
Output:
time in time out secs_in secs_out secs_diff mins_diff hour:min
19:30 19:30 1,328,553,000 1,328,553,000 0 0 00:00
19:30 19:31 1,328,553,000 1,328,553,060 60 1 00:01
19:30 23:35 1,328,553,000 1,328,567,700 14,700 245 04:05
19:30 01:35 1,328,553,000 1,328,574,900 21,900 365 06:05
19:30 03:35 1,328,553,000 1,328,582,100 29,100 485 08:05
19:30 05:35 1,328,553,000 1,328,589,300 36,300 605 10:05
19:30 07:35 1,328,553,000 1,328,596,500 43,500 725 12:05
19:30 19:29 1,328,553,000 1,328,639,340 86,340 1439 23:59