function tiempoAtras($timestamp, $days = false, $format = "M j, Y"){
if (!is_numeric($timestamp)) {
// It's not a time stamp, so try to convert it...
$timestamp = strtotime($timestamp);
}
if (!is_numeric($timestamp)) {
// If its still not numeric, the format is not valid
return false;
}
// Calculate the difference in seconds
$difference = time() - $timestamp;
// Check if we only want to calculate based on the day
if ($days && $difference < (60*60*24)) {
return "Hoy";
}
if ($difference < 3) {
return "Ahora mismo";
}
if ($difference < 60) {
return "hace ".$difference . " segundos";
}
if ($difference < (60*2)) {
return "hace 1 minuto";
}
if ($difference < (60*60)) {
return "hace ".intval($difference / 60) . " minutos";
}
if ($difference < (60*60*2)) {
return "hace 1 hora";
}
if ($difference < (60*60*24)) {
return "hace ".intval($difference / (60*60)) . " horas";
}
if ($difference < (60*60*24*2)) {
return "hace 1 día";
}
if ($difference < (60*60*24*7)) {
return "hace ".intval($difference / (60*60*24)) . " días";
}
if ($difference < (60*60*24*7*2)) {
return "hace 1 semana";
}
if ($difference < (60*60*24*7*(52/12))) {
return "hace ".intval($difference / (60*60*24*7)) . " semanas";
}
if ($difference < (60*60*24*7*(52/12)*2)) {
return "hace 1 mes";
}
if ($difference < (60*60*24*364)) {
return "hace ".intval($difference / (60*60*24*7*(52/12))) . " meses";
}
// More than a year ago, just return the formatted date
return @date($format, $timestamp);
}