Re: Help needed with calculation

From: Date: Sun, 15 Nov 2009 21:46:26 +0000
Subject: Re: Help needed with calculation
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-299854@lists.php.net to get a copy of this message
Chris Payne wrote:
Hi everyone, I'm not sure of the correct formula for this, if I have a file - just for example, that is 10245458756 bytes long and the download speed is 60KB a second, what formula would I use to calculate how many seconds/minutes/hours it would take to download the file? Maths really isn't my strong point and formulas go over my head otherwise I wouldn't ask :-( Thanks everyone Chris
$size = 1024548756; // in bytes $kb_per_sec = 60; // I assume you'll fill these in from elsewhere? $b_per_sec = $kb_per_sec * 1024; $seconds = $size / $b_per_sec; $minutes = 0; $hours = 0; if($seconds > 60) { // 60 seconds to a minute $minutes = (int)($seconds / 60); $seconds -= $minutes * 60; if($minutes > 60) {
    // 60 minutes to an hour
    $hours = (int)($minutes / 60);
    $minutes -= $hours * 60;
    // if you want to go further and calculate days, have at :)
} } You could also approach this using modulus, but if you're not confident with math, this might be a more intuitive approach.

« previous php.general (#299854) next »