How to check time entry and void calculation when it comes blank

3

I'm calculating the difference between two times using

asked by anonymous 18.08.2015 / 22:22

1 answer

2

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.

    
18.08.2015 / 23:02