note 78537 added to function.date
| From: | JoshL at osu1 dot php dot net | Date: | Tue, 16 Oct 2007 20:53:25 +0000 |
| Subject: | note 78537 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-131432@lists.php.net to get a copy of this message | ||
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
----
Server IP: 69.147.83.197
Probable Submitter: 63.226.246.158
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- https://master.php.net/note/edit/78537
Del: integrated -- https://master.php.net/note/delete/78537/integrated
Del: useless -- https://master.php.net/note/delete/78537/useless
Del: bad code -- https://master.php.net/note/delete/78537/bad+code
Del: spam -- https://master.php.net/note/delete/78537/spam
Del: non-english -- https://master.php.net/note/delete/78537/non-english
Del: in docs -- https://master.php.net/note/delete/78537/in+docs
Del: other reasons-- https://master.php.net/note/delete/78537
Reject -- https://master.php.net/note/reject/78537
Search -- https://master.php.net/manage/user-notes.php