-4

How can I calculate percentage between two time values in php: Completed time 4min. and 35sec. Maximum time 11min. What would the remaining 6min and 25sec be in percentage?

user3176519
  • 393
  • 1
  • 9
  • 16

2 Answers2

3

First, make those minutes into seconds:

4 min 35 sec = 275 seconds

11 min = 660 seconds

Your percentage of remaining time will be (275 / 660) * 100. The percentage of time left would be ((660 - 275) / 660) * 100. Of course, that's all in seconds. Don't know how you are receiving that time in php, but it might look like:

$maxTime = 660;
$timeTaken = 275;

$percentage = ($timeTaken / $maxTime) * 100;
// To get percentage of time left
$percentLeft = (($maxTime - $timeTaken) / $maxTime) * 100;
Captain Hypertext
  • 2,446
  • 4
  • 27
  • 36
2

If you have minutes and second separately, it will be:

$min = 4;
$sek = 35;
$maxmin = 11;
$percentage = round((60*$maxmin - (60*$min + $sek))/($maxmin*60)*100,2);

result is 58,33

n-dru
  • 9,285
  • 2
  • 29
  • 42