Tema: sumar horas
Ver Mensaje Individual
  #2 (permalink)  
Antiguo 22/03/2007, 15:53
elkronos
 
Fecha de Ingreso: septiembre-2004
Mensajes: 66
Antigüedad: 19 años, 7 meses
Puntos: 0
Re: sumar horas

Esto te servirá suerte

<?php
// Autor elkronos

function suma2horas($hora1,$hora2)
{
$totseg =0;$totmin=0;$tothora=0;
list($h1,$m1,$s1) = explode(":",$hora1);
list($h2,$m2,$s2) = explode(":",$hora2);

if(($s1 +$s2) > 59){

$totseg = 0;
$totmin++;


}else{
$totseg = $s1 +$s2;

}
$totmin += $m1 + $m2;

if($totmin > 59){

$totmin = 0;

$tothora++;
}
$tothora+= $h1 + $h2;


return ((strlen($tothora)==1)?"0$tothora":$tothora).":".( (strlen($totmin)==1)?"0$totmin":$totmin).":".((str len($totseg)==1)?"0$totseg":$totseg);
}

// USO
echo suma2horas("12:30:00","13:10:01");
?>

Última edición por elkronos; 22/03/2007 a las 15:54 Razón: me falto una parte