1
How best to calculate the difference of minutes between two camps input time
with PHP?
Example of two fields input
:
<label for="Cseg3">Horário 1:</label>
<input type="time" id="Cseg3" name="Tsegs">
<label for="Cseg4">Horário 2:</label>
<input type="time" id="Cseg4" name="Tsegss">
An attempt with Datetime::dif that didn’t work out:
<?php
setlocale(LC_ALL, 'pt_BR', 'pt_BR.utf-8', 'pt_BR.utf-8', 'portuguese');
date_default_timezone_set('America/Sao_Paulo');
$val1 = $_POST ["Tsegs"];
$val2 = $_POST ["Tsegss"];
$datetime1 = new DateTime($val1);
$datetime2 = new DateTime($val2);
$intervalo = $datetime1->diff($datetime2);
echo $intervalo;
?>
Browser inspecting error appears: localhost/php file path: 500 (Internal Server Error).