Sum of two values

Asked

Viewed 38 times

-1

I have two values:

Minuto1 = 00:00:00 e Minuto2 = 11:30:00

I’m using the substr to ignore the : and make the sum. See the example:

$minuto1 = substr("00:00:00",0,2)*60 + substr("00:00:00",3,2); 
$minuto2 = substr("11:30:00",0,2)*60 + substr("11:30:00",3,2); 

After that, I take the minutes that were worked:

$soma1 =  $minuto1 - $minuto2;

In case either of the two values are as 00:00:00, how can I make him return me after the sum instead of -200 one 0?

1 answer

0


You can use a ternary operator:

$soma1 > 0 ? $soma : 0;
  • 1

    Thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.