List Info

Thread: note 78537 added to function.date




note 78537 added to function.date
user name
2007-10-16 15:53:25
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  -- h
ttps://master.php.net/note/delete/78537/integrated
Del: useless     -- http
s://master.php.net/note/delete/78537/useless
Del: bad code    -- htt
ps://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     -- http
s://master.php.net/note/delete/78537/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/78537
Reject      -- https://mast
er.php.net/note/reject/78537
Search      -- https://
master.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


note 78537 deleted from function.date by nlopess
user name
2007-10-19 13:56:17
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

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )