56 lines
2.0 KiB
PHP
56 lines
2.0 KiB
PHP
<?php
|
|
/*
|
|
* Funciones de utilidad
|
|
*/
|
|
|
|
function fechaGuion($fechaTxt){//convierte fecha a guiones
|
|
$fechaTxt = trim($fechaTxt);
|
|
if(substr($fechaTxt,2,1) == "/" && substr($fechaTxt,5,1) == "/"){// dd/mm/aaaa
|
|
$fechaArr = explode("/", $fechaTxt);
|
|
return $fechaArr[2]."-".$fechaArr[1]."-".$fechaArr[0];
|
|
}
|
|
if(substr($fechaTxt,4,1) == "-" && substr($fechaTxt,7,1) == "-")// aaaa-mm-dd
|
|
return $fechaTxt;
|
|
return "";
|
|
}
|
|
function fechaSlash($fechaTxt){//convierte fecha a /
|
|
$fechaTxt = trim($fechaTxt);
|
|
if(substr($fechaTxt,2,1) == "/" && substr($fechaTxt,5,1) == "/"){// dd/mm/aaaa
|
|
return $fechaTxt;
|
|
}
|
|
if(substr($fechaTxt,4,1) == "-" && substr($fechaTxt,7,1) == "-"){// aaaa-mm-dd
|
|
$fechaArr = explode("-", $fechaTxt);
|
|
return $fechaArr[2]."/".$fechaArr[1]."/".$fechaArr[0];
|
|
}
|
|
return "";
|
|
}
|
|
|
|
function fechaTexto($fechaTxt, $showYear = true){//convierte fecha a cadena de texto
|
|
$fechaTxt = trim($fechaTxt);
|
|
if(substr($fechaTxt,2,1) == "/" && substr($fechaTxt,5,1) == "/"){// dd/mm/aaaa
|
|
$fechaArr = explode("/", $fechaTxt);
|
|
if($showYear)
|
|
return intval($fechaArr[0])." de ".mesNombre($fechaArr[1])." de ".$fechaArr[2];
|
|
else
|
|
return intval($fechaArr[0])." de ".mesNombre($fechaArr[1]);
|
|
}
|
|
if(substr($fechaTxt,4,1) == "-" && substr($fechaTxt,7,1) == "-"){// aaaa-mm-dd
|
|
$fechaArr = explode("-", $fechaTxt);
|
|
if($showYear)
|
|
return intval($fechaArr[2])." de ".mesNombre($fechaArr[1])." de ".$fechaArr[0];
|
|
else
|
|
return intval($fechaArr[2])." de ".mesNombre($fechaArr[1]);
|
|
}
|
|
return "";
|
|
}
|
|
|
|
function mesNombre($num){
|
|
$meses=array(1=>"enero", "febrero", "marzo", "abril", "mayo", "junio", "julio", "agosto", "septiembre", "octubre", "noviembre", "diciembre");
|
|
return $meses[intval($num)];
|
|
}
|
|
|
|
function diaNombre($num){
|
|
$dias=array("domingo", "lunes", "martes", "miércoles", "jueves", "viernes", "sábado");
|
|
return $dias[intval($num)];
|
|
}
|