Convert minutes to hours

Description PHP

Function to convert minutes to hours

The Code Download

  1. <?php
  2. function m2h($mins) {
  3.     if ($mins < 0) {
  4.         $min = Abs($mins);
  5.     } else {
  6.         $min = $mins;
  7.     }
  8.     $H = Floor($min / 60);
  9.     $M = ($min - ($H * 60)) / 100;
  10.     $hours = $H + $M;
  11.     if ($mins < 0) {
  12.         $hours = $hours * (-1);
  13.     }
  14.  
  15.     $expl = explode(".", $hours);
  16.     $H = $expl[0];
  17.     if (empty($expl[1])) {
  18.         $expl[1] = 00;
  19.     }
  20.  
  21.     $M = $expl[1];
  22.     if (strlen($M) < 2) {
  23.         $M = $M . 0;
  24.     }
  25.  
  26.     $hours = $H . "." . $M;
  27.  
  28.     return $hours;
  29. }
  30. ?>

Credits

Added by JC on 15th November 2007

Comments

There are no comments about this snippet.

Post Comment Github Markdown Supported

You must be logged in to post a comment.

Login here to post a comment