RE: [PHP] a little math

From: Date: Fri, 20 Apr 2007 09:03:00 +0000
Subject: RE: [PHP] a little math
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-253328@lists.php.net to get a copy of this message
> > maybe someone can figure why sometimes i get negative values for seconds.. > > $job['finished'] and $job['finished'] are both unix timestamp. > i subtract both to get how many seconds some thing took.. well you > should be able to read the rest. sometimes it works fine but other times > i get negative seconds. > > > $job['run_time'] = ($job['finished'] - $job['started']); > > $minutes = number_format($job['run_time'] / 60, 0, '', ''); > > // seconds left after calculating minutes > $seconds = (($job['run_time']- 60) * $minutes); > > $job['runtime'] = $minutes . ' mins ' . $seconds . ' secs'; > If $job['run_time'] < 60 then clearly $seconds will be negative. Why don't you use: $minutes = floor($job['run_time'] / 60); $seconds = $job['run_time'] % 60; Edward

« previous php.general (#253328) next »