0

Person a has an hourly rate of 9.500 (Yes three decimal places in our country)

He has worked for 8 hours and 15 minutes and 0 seconds which is in the format 08:15:00.

Im getting the variables as below

$iCostPerHour = '9.500';
$timespent = '08.15'; //i got this by converting from 08:15:00

How do i calculate the cost for this time?

Currently what i did is

echo number_format(($timespent * $iCostPerHour), 3, '.', ',')

And it is returing a wrong value.

What am i doing wrong here?

thowzif
  • 103
  • 2
  • 3
  • 12

1 Answers1

5
$iCostPerHour = 9.500;
$timespent = '08:15:00';
$timeparts=explode(':',$timespent);
$pay=$timeparts[0]*$iCostPerHour+$timeparts[1]/60*$iCostPerHour;
echo $pay;

Live demo https://eval.in/740789

Alexey Shatrov
  • 450
  • 4
  • 12