esupergood - format_time() function tweak


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



Copy this code and paste it in your HTML
  1. /* --> Dont paste this line <-- */
  2. $d = $time - $timestamp;
  3. if ($d < 60)
  4. return $d." second".(($d==1)?'':'s')." ago";
  5. else
  6. {
  7. $d = floor($d / 60);
  8. if($d < 60)
  9. return $d." minute".(($d==1)?'':'s')." ago";
  10. else
  11. {
  12. $d = floor($d / 60);
  13. if($d < 24)
  14. return $d." hour".(($d==1)?'':'s')." ago";
  15. else
  16. {
  17. $d = floor($d / 24);
  18. if($d < 7)
  19. return $d." day".(($d==1)?'':'s')." ago";
  20. else
  21. {
  22. $d = floor($d / 7);
  23. if($d < 4)
  24. return $d." week".(($d==1)?'':'s')." ago";
  25. }//Week
  26. }//Day
  27. }//Hour
  28. }//Minute

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.