Ejemplo:
HORA INICIAL: 07:00:00 am
HORA FINAL: 11:59:01 am
El resultado será: 04:59:01 HORAS han pasado entre : 07:00:00 y 11:59:01
- Un método llamado: calcula_horas_totales() .
- Y una llamada al método.
<?php function calcula_horas_totales($hora_inicial, $hora_final) { $total_segundos = strtotime($hora_final) - strtotime($hora_inicial); $horas = floor ( $total_segundos / 3600 ); $minutos = ( ( $total_segundos / 60 ) % 60 ); $segundos = ( $total_segundos % 60 ); $time['horas'] = str_pad( $horas, 2, "0", STR_PAD_LEFT ); $time['minutos'] = str_pad( $minutos, 2, "0", STR_PAD_LEFT ); $time['segundos'] = str_pad( $segundos, 2, "0", STR_PAD_LEFT ); $time = implode( ':', $time ); return $time; }//fin funcion $hora_inicial = '07:00:00'; $hora_final = '11:59:01'; //EJECUTO LA FUNCIÓN y asigno resultado a una variable $resultado = calcula_horas_totales( $hora_inicial , $hora_final ); //IMPRIMO RESULTADO echo $resultado, ' HORAS han pasado entre : '.$hora_inicial.' y '.$hora_final; ?>