Page 1 of 1

Newbie question about converting minutes to hours

Posted: Thu Jun 10, 2010 3:44 pm
by someonehere
Hello
Please, complete newbie question, but I have a page that takes the information in minutes from MySQL and displays it in hours. The problem is that I'd like for it not to display either the hours or the minutes when they equal 0, for example, currently, when something is 120 minutes, it displays 2h 0m , and when it's 45 minutes it displays 0h 45m. Is there any way those could display simply as 2h or as 45m? The code I am using is below:

if ($row["runtimem"]<>""){
$runh = floor($row["runtimem"] / 60);
$runm = $row["runtimem"] % 60;
echo $runh . "h " . $runm . "m&nbsp;&nbsp;&nbsp;";
}


Please, any ideas would be very appreciated.

Re: Newbie question about converting minutes to hours

Posted: Thu Jun 10, 2010 3:52 pm
by cpetercarter

Code: Select all

if ($row["runtimem"]<>""){
       $runh = floor($row["runtimem"] / 60);
       $runm = $row["runtimem"] % 60;
       $run = "";
       if ($runh > 0) $run .= $runh . "h ";
       if ($runm > 0) $run .= $runm . "m";
       $run = trim($run) . "&nbsp;&nbsp;&nbsp;"; 
       echo $run;
}