Ivan Velchev Ivan Velchev - 1 year ago 103
PHP Question

Multiplying INT and TIME

I have to do some calculations which include variables of type INT and TIME. Something like this:

$A = 555;
$B = 0.555;
$C = '08:00:00';
$D = '06:45:56';

$E = $A * exp(-$B * ($C - $D) * 24);
echo "RESULT: " . $E;

How should I refactor the TIME type variables in order to make it work?


@mlewis54 Gave the right answer but just in case anyone else is facing the same problem - notice you have to consider that strtotime() converts time into seconds so you will need to later convert these seconds into whatever you need (minutes/hours/days).

So instead of multiplying by 24 I had to divide by 3600 in my case in order to make it work.

$E = $A * exp(-$B * (($C - $D) / 3600));

Answer Source

You should convert the $C and $D to ints and then do the math. Something like:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download