I asked the same question, but I want to know where the error is, since it does not return the time difference.
obs: I want you to show the time difference. example: 7:50:10 - 7:50:00 = 00:00:10, but that was not the result. It is not returning anything.
code:
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<?php
include "../../conexao.php";
// primeira parte 1
$sql = "SELECT * FROM tempo";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$id = $row["id"];
$tempo1 = $row["tempo"];
echo "$tempo1 <br>";
$sql = "DELETE FROM tempo WHERE id='$id'";
if ($conn->query($sql) === TRUE) {
} else {
echo "Erro ao tentar deletar: " . $conn->error;
}
// segunda parte 2.2
$sql = "SELECT * FROM tempo2";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$id1 = $row["id"];
$corrida = $row["corrida"];
$nome1 = $row["nome"];
$numero = $row["numero"];
$tempo2 = $row["tempo"];
echo "$tempo2 <br>";
$sql = "DELETE FROM tempo2 WHERE id='$id1'";
if ($conn->query($sql) === TRUE) {
} else {
echo "Erro ao tentar deletar: " . $conn->error;
}
function dateDiff( $tempo1, $tempo2, $format = '%H:%i:%s' ) {
$d1 = new DateTime( $tempo1 );
$d2 = new DateTime( $tempo2 );
//Calcula a diferença entre as datas
$diff = $d1->diff($d2, true);
//Formata no padrão esperado e retorna
return $diff->format( $format );
}
}
}
?>
</body>
</html>