note 32130 added to function.date

From: Date: Sun, 18 May 2003 14:59:21 +0000
Subject: note 32130 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-48524@lists.php.net to get a copy of this message
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; } ?> -- Manual Page -- http://www.php.net/manual/en/function.date.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32130 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32130&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32130&report=yes

« previous php.notes (#48524) next »