note 66258 added to function.date

From: Date: Thu, 18 May 2006 01:02:59 +0000
Subject: note 66258 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-111535@lists.php.net to get a copy of this message
/* 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); } ---- Server IP: 84.18.202.180 Probable Submitter: 81.178.227.179 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- http://master.php.net/note/edit/66258 Del: integrated -- http://master.php.net/note/delete/66258/integrated Del: useless -- http://master.php.net/note/delete/66258/useless Del: bad code -- http://master.php.net/note/delete/66258/bad+code Del: spam -- http://master.php.net/note/delete/66258/spam Del: non-english -- http://master.php.net/note/delete/66258/non-english Del: in docs -- http://master.php.net/note/delete/66258/in+docs Del: other reasons-- http://master.php.net/note/delete/66258 Reject -- http://master.php.net/note/reject/66258 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#111535) next »