Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Ricardo m. García

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

PHP : Hace Script / Ago Script

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

function hace($timestamp)
{
$diferencia = time() - $timestamp;
	if($diferencia > 0)
	{
$periodo = array("segundo", "minuto", "hora", "dia", "semana", "mes" , "año", "decada");
$longitud = array(           "60"    , "60"  , "24" , "7"     , "4.35", "12"       , "10"    );
	
	for($j = 0; $diferencia >= $longitud[$j]; $j++)
	$diferencia /= $longitud[$j];
	
	$diferencia = round($diferencia);
	
	if($diferencia != 1)
	{
		if($periodo[$j] == "mes")
		$periodo[$j].= "es";
		else
		$periodo[$j].= "s";
	}
	
	return "Hace <b>".$diferencia."</b> ".$periodo[$j];
	}
}
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS