What is the best way to calculate the difference of minutes between two input time
fields 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 did not work:
<?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;
?>
Inserting the browser appears the error: localhost / file path php: 500 (Internal Server Error).