note 59436 added to function.strftime

From: Date: Wed, 07 Dec 2005 01:54:26 +0000
Subject: note 59436 added to function.strftime
Groups: php.notes 
Request: Send a blank email to php-notes+get-99659@lists.php.net to get a copy of this message
This function is useful for news posts. It displays the creation date and elapsed time like: Sunday, December 4, 2005 - 2 days ago Monday, December 5, 2005 - Yesterday Monday, November 28, 2005 - 1 week ago Friday, October 28, 2005 - 6 weeks ago function off($date){ $date = strtotime($date); $offset = (strftime("%j")+strftime("%Y")*365)- (strftime("%j",$date)+strftime("%Y",$date)*365); if ($offset>7){ $offset = (strftime("%V")+strftime("%Y")*52)- (strftime("%V",$date)+strftime("%Y",$date)*52); $end=($offset!=0?($offset>1?$offset . " weeks ago":"a week ago"):"Today"); } else $end=($offset!=0?($offset>1?"$offset days ago":"Yesterday"):"Today"); return strftime("%A, %B %e, %Y",$date)." - ". $end; } To insert the time: <?=off("12/4/05")?> ---- Manual Page -- http://www.php.net/manual/en/function.strftime.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+59436 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59436&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59436&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59436&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59436&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59436&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59436&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59436&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+59436&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#99659) next »