Hi there,

Im creating a job sheet system, where people enter how many minutes they have spent on a job.
The minutes are totaled up and im left with a total like: 465 (minutes).
I need something that will break that down into hours. (465 minutes is equal to 7 hours and 45 mins).
If I try this calculation: 465 / 60 it equals 7.75. It needs to be 7.45 and I cant find the answer anywhere 

Any help would be massively appreciated

    Space Cowboy wrote:

    The minutes are totaled up and im left with a total like: 465 (minutes).
    I need something that will break that down into hours. (465 minutes is equal to 7 hours and 45 mins).
    If I try this calculation: 465 / 60 it equals 7.75. It needs to be 7.45 and I cant find the answer anywhere

    7.75 hours is 7 hours and 0.75 hours. Since 0.75 hours is 0.75 * 60 = 45 minutes... you get 7 hours 45 minutes. So, if you are writing a program to do this, you might compute 465 mod 60 to give you 45 minutes, and compute with integer division 465 / 60 = 7 hours. (In the case of PHP, you can simply cast the result to int to get the truncation that results from integer division).

      
      // function to convert minutes into hours and minutes for a jobsheet.
      function timer($job)
      { 
      $hours =  floor($job/60); // No. of mins/60 to get the hours and round down
      $mins =   $job % 60; // No. of mins/60 - remainder (modulus) is the minutes
      echo "Job = " . $hours . " Hours " . $mins . " Minutes ";
      }
      // usage: wrap the function around your number of minutes:
      timer(465);
      
      

        If you want to do it that way, then it would be better as:

        // function to convert minutes into hours and minutes for a jobsheet.
        function convertFromMinutes($job_duration)
        {
            $hours = (int)($job_duration / 60);
            $minutes = $job_duration - ($hours * 60);
            return array('hours' => $hours, 'minutes' => $minutes);
        }
        
        $job_duration = 465;
        $job_duration = convertFromMinutes($job_duration);
        echo "Job duration = " . $job_duration['hours'] . " Hours "
            . $job_duration['minutes'] . " Minutes ";
          Write a Reply...