calculate minutes into hours
Results 1 to 4 of 4

Thread: calculate minutes into hours

  1. #1
    Junior Member
    Join Date
    Aug 2007
    Posts
    23

    Exclamation calculate minutes into hours

    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

  2. #2
    PHP Witch laserlight's Avatar
    Join Date
    Apr 2003
    Location
    Singapore
    Posts
    13,461
    Quote Originally Posted by Space Cowboy
    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).
    Use Bazaar for your version control system
    Read the PHP Spellbook
    Learn How To Ask Questions The Smart Way

  3. #3
    count($dracula) rikmoncur's Avatar
    Join Date
    Apr 2005
    Location
    Scotland
    Posts
    377
    PHP Code:

    // 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); 
    Last edited by rikmoncur; 03-24-2009 at 08:44 AM.

  4. #4
    PHP Witch laserlight's Avatar
    Join Date
    Apr 2003
    Location
    Singapore
    Posts
    13,461
    If you want to do it that way, then it would be better as:
    PHP Code:
    // 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 "
    Use Bazaar for your version control system
    Read the PHP Spellbook
    Learn How To Ask Questions The Smart Way

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •