martes, 29 de octubre de 2013

php suma y resta horas

date_default_timezone_set('Europe/Madrid');

$Hora = Time(); // Hora actual  
echo date('H:i:s',$Hora);     

$Hora = Time() + (60 *60 * -1);  
echo "<br>";
echo date('H:i:s',$Hora); //  -1 hora

$Hora = Time() + (60 *60 * 2);  
echo "<br>";
echo date('H:i:s',$Hora); //  +2 hora


....  O TAMBIEN

$Hora = strtotime('14:00:01') + (60 *60 * -1); ;
echo date('H:i:s',$Hora);   


.... O EN FUNCION

//***************************************************
function sumaRestaHoras($hora, $incremento)
{
$hora = strtotime($hora) + (60 *60 * $incremento);

return date('H:i:s',$hora);
}

echo sumaRestaHoras('14:00:01',-5);
 






.

php suma a una fecha un numero de dias

function suma_fechas($fecha,$ndias)
{
    if (preg_match("/[0-9]{1,2}\/[0-9]{1,2}\/([0-9][0-9]){1,2}/",$fecha))
    list($dia,$mes,$anyo)=split("/", $fecha);

    if (preg_match("/[0-9]{1,2}-[0-9]{1,2}-([0-9][0-9]){1,2}/",$fecha))
    list($dia,$mes,$anyo)=split("-",$fecha);

    $nueva = mktime(0,0,0, $mes,$dia,$anyo) + $ndias * 24 * 60 * 60;
    $nuevafecha=date("d/m/Y",$nueva);

    return ($nuevafecha);
}

lunes, 28 de octubre de 2013

JAVASCRIPT saber la altura del body


var alto=window.innerHeight;



 


//***
// si queremos cambiar la altura de un DIV por ejemplo.


alto=alto-500;
document.getElementById("div1").style.height=alto+'px';