I'm calculating the difference between two times using
I'm calculating the difference between two times using
I believe you have to do the verification before doing everything. Type:
//se for diferente de null, faz o calculo
if ($val1 <> null and $val2 <> null) {
$datetime1 = new DateTime("2017-04-05, $val1");
$datetime2 = new DateTime("2017-05-06, $val2");
$horario1 = $intervalo->h; // DIFERENÇA EM HORAS (INT)
$horario2 = $intervalo->i; // PEGA OS MINUTOS
}
If one of the two equals NULL, it does nothing.