note 89444 added to function.date
| From: | davet15 at hotmail dot com | Date: | Sun, 08 Mar 2009 04:13:52 +0000 |
| Subject: | note 89444 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-151619@lists.php.net to get a copy of this message | ||
There is probably a much easier way to do this, but this function works.
This will return the approximate time elapsed since the unix_timestamp fed to it, in this format:
1 minute ago
x:xx (xx minutes ago)
x:xx (x hours ago)
x/x/x (x hours ago) [ if not the same date]
x/x/x (x days ago)
x/x/x (x years ago)
The function:
function getLastUpdate($date){
$time = time();
$d = $time - $date;
if($d < 60){
return "Less than 1 minute ago.";
}
if($d < 3600){
$result = floor($d/60);
$plural = ($result > 1) ? "s" : "";
return date('g:ia',$date)." ($result minute$plural ago)";
}
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:ia',$date);
return "$text ($result hour$plural ago)";
}
if($d < 2592000){
$result = floor($d/(60*60*24));
$plural = ($result > 1) ? "s" : "";
return date('n/j/y',$date)." ($result day$plural ago)";
}
$result = floor($d/(60*60*24*30));
$plural = ($result > 1) ? "s" : "";
return date('n/j/y',$date)." ($result year$plural ago)";
}
----
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/89444
Del: integrated -- https://master.php.net/note/delete/89444/integrated
Del: useless -- https://master.php.net/note/delete/89444/useless
Del: bad code -- https://master.php.net/note/delete/89444/bad+code
Del: spam -- https://master.php.net/note/delete/89444/spam
Del: non-english -- https://master.php.net/note/delete/89444/non-english
Del: in docs -- https://master.php.net/note/delete/89444/in+docs
Del: other reasons-- https://master.php.net/note/delete/89444
Reject -- https://master.php.net/note/reject/89444
Search -- https://master.php.net/manage/user-notes.php