これを実行するための良い方法は、秒単位で考えることです。
最初のステップは、SQLでタイムスタンプの差を秒単位で取得することです($ dbcは私のデータベース接続です)。
$timeQuery= mysqli_query($dbc,
"SELECT TIMESTAMPDIFF(second,TIME1,TIME2) AS DIFF,
そしてそれを変数に割り当てます
while ($row = mysqli_fetch_array($timeQuery)) {
$totalTime = $row["DIFF"];
そして、変換を開始します。
//Seconds in an hour
$unith =3600;
//Seconds in a minute
$unitm =60;
//Number of hours and then the seconds remaining for minute calc
$hh = intval($totalTime / $unith);
$ss_remaining = ($totalTime - ($hh * 3600));
//Number of minutes and then the seconds remaing
$mm = intval($ss_remaining / $unitm);
$ss = ($ss_remaining - ($mm * 60));
そして、あなたはそれを次のように印刷することができます:
$hh . ' : ' . $mm . ' : ' . $ss