Hola he creado esta funcion:
Código PHP:
<?php
function dateDiff($from,$to) {
$diff = $to - $from;
$info = array();
if($diff>315569260) {
// Decadas
$info['decadas'] = ($diff - ($diff%315569260))/315569260;
$diff = $diff%315569260;
}
elseif($diff>31556926) {
// Años
$info['años'] = ($diff - ($diff%31556926))/31556926;
$diff = $diff%31556926;
}
elseif($diff>2629743) {
// Meses
$info['meses'] = ($diff - ($diff%2629743))/2629743;
$diff = $diff%2629743;
}
elseif($diff>604800) {
// Semanas
$info['semanas'] = ($diff - ($diff%604800))/604800;
$diff = $diff%604800;
}
elseif($diff>86400) {
// Dias
$info['dias'] = ($diff - ($diff%86400))/86400;
$diff = $diff%86400;
}
elseif($diff>3600) {
// Horas
$info['horas'] = ($diff - ($diff%3600))/3600;
$diff = $diff%3600;
}
elseif($diff>60) {
// Minutos
$info['minutos'] = ($diff - ($diff%60))/60;
$diff = $diff%60;
}
elseif($diff>0) {
// Segundos
$info['segundos'] = $diff;
}
$f = '';
foreach($info as $k=>$v) {
if($v>0) $f .= "$v $k, ";
}
return substr($f,0,-2);
}
?>
para usarlo tienes que poner esto:
Código PHP:
<?php
$date = "2009-4-02 11:16:30"; // aca va la fecha de cuando se inserto los registros
$fecha = preg_replace('/:[0-9][0-9][0-9]/','',$date);
$time = strtotime($fecha);
echo "Hace ";
echo dateDiff($time,time());
?>