IT & Programming

Convert minutes to hours with PHP

  • Convert minutes to hours.
  • How to convert minutes to hours with php.
  • Calculate hours from minutes.

Function accepts 2 parameters. Hours and the minutes. Then it converts minutes to hours.

Function

function minToHours($hour, $min) {

  if (($min-60) < 0) {
  
    $total = "$hour:$min";	
    return $total;
	
  }  else {

    $min -= 60;
    $hour += 1;
    minToHours($hour, $min);
  }
}

Calling The Function

echo minToHour(4,433);

Output

11:30

Leave A comment

Email address is optional and will not be published. Only add email address if you want a reply from blog author.
Please fill required fields marked with *