note 78537 deleted from function.date by nlopess

From: Date: Fri, 19 Oct 2007 18:56:17 +0000
Subject: note 78537 deleted from function.date by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-131560@lists.php.net to get a copy of this message
Note Submitter: Josh L ---- Thought it would be nice for users to see a date/time that was more useful than a simple stamp. Feel free to use this Cute Date... <?php /* Function to display a super user-friendly date string * (i.e. "17 minutes ago", "a week ago", "last Thursday") * made by Josh from Double Thought */ function cuteDate($compared) { $today= time(); // get it $diff= $today-$compared; // subtract it // return the cute string switch($diff) { case $diff < 120 : // ----------------------- Seconds (up to 2 minutes) return 'a moment ago'; break; case $diff < 3660 : // ----------------------- Minutes return number_format($diff/60).' minutes ago'; break; case $diff < 86400 : // ----------------------- Hours return number_format($diff/3600).' hours ago'; break; case $diff < 518400 : // ----------------------- Days still in the week return 'last '.date('l',$compared); // (lowercase L = long / uppercase D = short) break; case $diff < 604800 : // ----------------------- One week ago today return 'a week ago'; break; case $diff < 1123200 : // ----------------------- Within two weeks return number_format($diff/86400).' days ago'; break; case $diff < 1209600 : // ----------------------- Two weeks ago today return 'two weeks ago'; break; case $diff < 31449600 : // ----------------------- This year return date('F jS',$compared); // (uppercase M = short / uppercase F = long) break; case $diff < 31536000 : // ----------------------- Exactly a year ago return 'a year ago today'; break; default : // ----------------------- Over a year ago return date("F jS, 'y",$compared); // (uppercase M = short / uppercase F = long) break; } } ?> http://www.dbltht.com/cutedate

« previous php.notes (#131560) next »