Friendly date display


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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. }

URL: http://kawika.org

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.