Your Ad Here

Posted By

kawikak on 05/22/09


Tagged

php date


Versions (?)

Friendly date display


 / Published in: PHP
 

URL: http://kawika.org

  1. /*
  2. Display the date in a friendly manner
  3.  */
  4. function subtleDate ($time, $day_limit = 5, $long_format = 'M j')
  5. {
  6. $_DAY = 60*60*24;
  7. $diff = mktime() - strtotime($time);
  8.  
  9. switch ($diff)
  10. {
  11. case ($diff < $_DAY): return 'Today';
  12. case ($diff < $_DAY*2): return 'Yesterday';
  13. case (floor($diff/$_DAY) < $day_limit): return floor(($diff/$_DAY)) . ' days ago';
  14. default: return date($long_format, strtotime($time));
  15.  
  16. }
  17. }

Report this snippet  

You need to login to post a comment.