note 32130 deleted from function.date by sniper
| From: | sniper@php.net | Date: | Sat, 11 Oct 2003 16:53:55 +0000 |
| Subject: | note 32130 deleted from function.date by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-58292@lists.php.net to get a copy of this message | ||
Note Submitter: matthijs@schoolnews.nl
----
I first used the VERY easy way to calculate date differences, but since I had to calculate 250+
differences, the execution time exceeded 30 seconds cause of all the loops. So I added a few
improvements to fasten up the function, no more loops :)
<?
function dateDiff($row){
$s = $row["nu"] - $row["lastpost"];
$m = intval($s/60);
$s = $s % 60;
$h = intval($m/60);
$m = $m % 60;
$d = intval($h/24);
$h = $h % 24;
$diff = "";
if ( !$d == "0" ) {
$diff = $diff . "$d days ";
} if ( !$h == "0" ) {
$diff = $diff . "$h hours ";
} if ( !$m == "0" ) {
$diff = $diff . "$m minutes ";
} if ( !$s == "0" ) {
$diff = $diff . "$s seconds ";
} if ( $diff == "" ) {
$diff = "-";
}
trim ($diff);
return $diff;
}
?>