note 66258 deleted from function.date by bobby
| From: | bobby@php.net | Date: | Thu, 07 Sep 2006 17:51:26 +0000 |
| Subject: | note 66258 deleted from function.date by bobby | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-116850@lists.php.net to get a copy of this message | ||
Note Submitter: tam at zenology dot co dot uk
----
/* Here's a simple function which takes a UNIX timestamp and returns a fuzzy date string such
as 'Yesterday 10:24', 'Wednesday 23:11', 'April 12' or 'June
2003'. It's only set up to handle dates in the past but it's easy to see how to
extend it to do future dates too. */
function fuzzyDate($timestamp)
{
if($timestamp > time())
//we don't handle future dates
return date('Y-m-d H:i', $timestamp);
elseif($timestamp > mktime(0,0,0))
//since midnight so it's today
return 'Today '.date('H:i', $timestamp);
elseif($timestamp > mktime(0,0,0) - 86400)
//since midnight 1 day ago so it's yesterday
return 'Yesterday '.date('H:i', $timestamp);
elseif($timestamp > mktime(0,0,0) - 86400*7)
//since midnight 7 days ago so it's this week
return date('l H:i', $timestamp);
elseif($timestamp > mktime(0,0,0,1,1))
//since 1st Jan so it's this year
return date('F j', $timestamp);
else
//ages ago!
return date('F Y', $timestamp);
}