note 89547 added to function.date

From: Date: Fri, 13 Mar 2009 02:36:50 +0000
Subject: note 89547 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-151814@lists.php.net to get a copy of this message
Correction to my function below for calculating the time elapsed since a unix timestamp fed to the function. The original function would have failed at months. Here is the function fixed: function getLastUpdate($date){ $time = time(); $d = $time - $date; if($d < 60){ return "1 minute ago"; } if($d < 3600){ $result = floor($d/60); $plural = ($result > 1) ? "s" : ""; return date('g:i a',$date)." <span class=\"soft\">($result minute$plural ago)</span>"; } if($d < 86400){ $result = floor($d/(60*60)); $plural = ($result > 1) ? "s" : ""; $text = (date('n/j/y',$date) != date('n/j/y',$time)) ? date('n/j/y',$date) : date('g:i a',$date); return "$text <span class=\"soft\">($result hour$plural ago)</span>"; } if($d < 2592000){ $result = floor($d/(60*60*24)); $plural = ($result > 1) ? "s" : ""; return date('n/j/y',$date)." <span class=\"soft\">($result day$plural ago)</span>"; } if($d < 311004000){ $result = floor($d/(60*60*24*30)); $plural = ($result > 1) ? "s" : ""; return date('n/j/y',$date)." <span class=\"soft\">($result month$plural ago)</span>"; } $result = floor($d/(60*60*24*30*12)); $plural = ($result > 1) ? "s" : ""; return date('n/j/y',$date)." <span class=\"soft\">($result year$plural ago)</span>"; } ---- Server IP: 69.147.83.197 Probable Submitter: 72.187.37.35 ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- https://master.php.net/note/edit/89547 Del: integrated -- https://master.php.net/note/delete/89547/integrated Del: useless -- https://master.php.net/note/delete/89547/useless Del: bad code -- https://master.php.net/note/delete/89547/bad+code Del: spam -- https://master.php.net/note/delete/89547/spam Del: non-english -- https://master.php.net/note/delete/89547/non-english Del: in docs -- https://master.php.net/note/delete/89547/in+docs Del: other reasons-- https://master.php.net/note/delete/89547 Reject -- https://master.php.net/note/reject/89547 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#151814) next »