Posted By

willcodeforfood on 12/16/07


Tagged


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

skywalker
adix
Abe
Nix


Hace Script / Ago Script


 / Published in: PHP
 

URL: http://snippets.dzone.com/posts/show/4674

Hace Script / Ago Script if we call with a timestamp of a month ago, he print "Hace 1 mes". If you want this in english should traduction. Sorry my english

http://snippets.dzone.com/posts/show/4674

  1. function hace($timestamp)
  2. {
  3. $diferencia = time() - $timestamp;
  4. if($diferencia > 0)
  5. {
  6. $periodo = array("segundo", "minuto", "hora", "dia", "semana", "mes" , "año", "decada");
  7. $longitud = array( "60" , "60" , "24" , "7" , "4.35", "12" , "10" );
  8.  
  9. for($j = 0; $diferencia >= $longitud[$j]; $j++)
  10. $diferencia /= $longitud[$j];
  11.  
  12. $diferencia = round($diferencia);
  13.  
  14. if($diferencia != 1)
  15. {
  16. if($periodo[$j] == "mes")
  17. $periodo[$j].= "es";
  18. else
  19. $periodo[$j].= "s";
  20. }
  21.  
  22. return "Hace <b>".$diferencia."</b> ".$periodo[$j];
  23. }
  24. }

Report this snippet  

You need to login to post a comment.