Snippets v2

Languages
My Snippets

Convert minutes to hours Login or Register to Bookmark this snippet

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 Contact JC

Added by JC on 14th November, 2007

Comments

There are no comments about this snippet.

Post Comment HTML is allowed

You must be registered and logged in to post a comment.

Login here to post a comment