Revision: 44414
Updated Code
at April 11, 2011 12:13 by linkmoises
Updated Code
<?php
function tiempo_transcurrido($fecha) {
if(empty($fecha)) {
return "No hay fecha";
}
$intervalos = array("segundo", "minuto", "hora", "dÃÂa", "semana", "mes", "año");
$duraciones = array("60","60","24","7","4.35","12");
$ahora = time();
$Fecha_Unix = strtotime($fecha);
if(empty($Fecha_Unix)) {
return "Fecha incorrecta";
}
if($ahora > $Fecha_Unix) {
$diferencia = $ahora - $Fecha_Unix;
$tiempo = "Hace";
} else {
$diferencia = $Fecha_Unix - $ahora;
$tiempo = "Dentro de";
}
for($j = 0; $diferencia >= $duraciones[$j] && $j < count($duraciones)-1; $j++) {
$diferencia /= $duraciones[$j];
}
$diferencia = round($diferencia);
if($diferencia != 1) {
$intervalos[5].="e"; //meses... la magia del español
$intervalos[$j].= "s";
}
return "$tiempo $diferencia $intervalos[$j]";
}
// Ejemplos de uso
// fecha en formato yyyy-mm-dd
// echo tiempo_transcurrido('2010/02/05');
// fecha y hora
echo tiempo_transcurrido('2011/02/21 21:37:00');
?>
Revision: 44413
Updated Code
at April 11, 2011 12:11 by linkmoises
Updated Code
<?php
function tiempo_transcurrido($fecha) {
if(empty($fecha)) {
return "No hay fecha";
}
$intervalos = array("segundo", "minuto", "hora", "dÃÂa", "semana", "mes", "año");
$duraciones = array("60","60","24","7","4.35","12");
$ahora = time();
$Fecha_Unix = strtotime($fecha);
if(empty($Fecha_Unix)) {
return "Fecha incorracta";
}
if($ahora > $Fecha_Unix) {
$diferencia =$ahora - $Fecha_Unix;
$tiempo = "Hace";
} else {
$diferencia = $Fecha_Unix -$ahora;
$tiempo = "Dentro de";
}
for($j = 0; $diferencia >= $duraciones[$j] && $j < count($duraciones)-1; $j++) {
$diferencia /= $duraciones[$j];
}
$diferencia = round($diferencia);
if($diferencia != 1) {
$intervalos[5].="e"; //meses... la magia del español
$intervalos[$j].= "s";
}
return "$tiempo $diferencia $intervalos[$j]";
}
// Ejemplos de uso
// fecha en formato yyyy-mm-dd
// echo tiempo_transcurrido('2010/02/05');
// fecha y hora
echo tiempo_transcurrido('2011/02/21 21:37:00');
?>
Revision: 44412
Updated Code
at April 11, 2011 12:10 by linkmoises
Updated Code
<?php
function tiempo_transcurrido($fecha) {
if(empty($fecha)) {
return "No hay fecha";
}
$intervalos = array("segundo", "minuto", "hora", "dÃa", "semana", "mes", "año");
$duraciones = array("60","60","24","7","4.35","12");
$ahora = time();
$Fecha_Unix = strtotime($fecha);
if(empty($Fecha_Unix)) {
return "Fecha incorracta";
}
if($ahora > $Fecha_Unix) {
$diferencia =$ahora - $Fecha_Unix;
$tiempo = "Hace";
} else {
$diferencia = $Fecha_Unix -$ahora;
$tiempo = "Dentro de";
}
for($j = 0; $diferencia >= $duraciones[$j] && $j < count($duraciones)-1; $j++) {
$diferencia /= $duraciones[$j];
}
$diferencia = round($diferencia);
if($diferencia != 1) {
$intervalos[5].="e"; //meses... la magia del español
$intervalos[$j].= "s";
}
return "$tiempo $diferencia $intervalos[$j]";
}
// Ejemplos de uso
// fecha en formato yyyy-mm-dd
// echo tiempo_transcurrido('2010/02/05');
// fecha y hora
echo tiempo_transcurrido('2011/02/21 21:37:00');
?>
Revision: 44411
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at April 11, 2011 12:04 by linkmoises
Initial Code
<?php
function tiempo_atras($date) {
if(empty($date)) {
return "No hay fecha";
}
$periods = array("segundo", "minuto", "hora", "dÃa", "semana", "mes", "año", "decada");
$lengths = array("60","60","24","7","4.35","12","10","10");
$now = time();
$unix_date = strtotime($date);
if(empty($unix_date)) {
return "Formato incorrecto";
}
if($now > $unix_date) {
$difference = $now - $unix_date;
$tense = "atrás";
}
for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
$difference /= $lengths[$j];
}
$difference = round($difference);
if($difference != 1){
$periods[5].="e"; //MESES
$periods[$j].= "s";
}
return "$difference $periods[$j] {$tense}";
}
?>
Initial URL
Initial Description
Initial Title
Hace x tiempo atrás
Initial Tags
date
Initial Language
PHP