Skip to content

Instantly share code, notes, and snippets.

@alejandrolechuga
Created April 6, 2012 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alejandrolechuga/2322663 to your computer and use it in GitHub Desktop.
Save alejandrolechuga/2322663 to your computer and use it in GitHub Desktop.
guia php
function convertir($fecha) {
$months = array();
$months [] = "Enero";
$months [] = "Febrero";
$months [] = "Marzo";
$months [] = "Abril";
$months [] = "Mayo";
$months [] = "Junio";
$months [] = "Julio";
$months [] = "Agosto";
$months [] = "Septiembre";
$months [] = "Octubre";
$months [] = "Noviembre";
$months [] = "Diciembre";
$diferencia = time() - $fecha;
$tiempo;
if ($diferencia < 60) {
$tiempo = "Hace menos de 1 minuto.";
} else {
if ($diferencia < 60*60) {
$tiempo = "Hace ".(int) date("i", $diferencia);
}
if (date("i", $diferencia) == 1) {
$tiempo .= " minuto.";
} else {
$tiempo .= " minutos.";
}
} else {
if ($diferencia < 60*60*24) {
$tiempo = "Hace ".(int) date("H", $diferencia);
if (date("H", $diferencia) == 1) {
$tiempo .= " hora.";
} else {
$tiempo .= " horas.";
}
} else {
$hora = (int) date("H", $fecha).":".date("i", $fecha);
$tiempo = $months[(int) date("m", $fecha) - 1]." ".(int) date("d", $fecha)." de ".date("Y", $fecha);
if (date("G", $fecha) < 13) {
$hora .= " am.";
} else {
$hora .= " pm.";
}
if (date("H", $fecha) == 1) {
$tiempo .= " a la ". $hora;
} else {
$tiempo .= " a las ". $hora;
}
}
}
}
return $tiempo;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment