ejemplo:
Hora 1: 04:50:01
Hora 2: 02:51:02
Resultado Esperado:
Faltan: 01:59:01
falta 1 hora 59 minutos y 1 segundo para que llegue a la hora 2...
lo que quiero hacer es conseguir el tiempo transcurrido.. pero no logro llegar al resultado...
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin título</title>
</head>
<body>
<?php
function fechadif($date1,$date2,$tipo){
$s = strtotime($date1)-strtotime($date2);
// tiempo en segundos
$difsegundos = $s;
$difsegundosm = intval($difsegundos);
$difminutom=intval($difsegundos/60);
$difhoram = intval(($difsegundos/60)/60);
// todo como predeterminado
$hora=date("H:i:s",$difsegundos);
$diferencia = $hora;
if($tipo == 'segundos'){
$diferencia = $difsegundosm;
}
if($tipo == 'minutos'){
$diferencia = $difminutom;
}
if($tipo == 'horas'){
$diferencia = $difhoram;
}
return $diferencia;
}
?>
<?php
$date1="2009-06-02 04:50:01";
$date2="2009-06-02 02:51:02";
?>
Diferencia de fechas:<br />
Fecha 1: <?php echo $date1 ?><br />
Fecha 2: <?php echo $date2 ?><br /><br />
Segundos: <?php echo fechadif($date1,$date2,'segundos'); ?><br />
Minutos: <?php echo fechadif($date1,$date2,'minutos'); ?><br />
Horas: <?php echo fechadif($date1,$date2,'horas'); ?><br />
Todo: <?php echo fechadif($date1,$date2,'todo'); ?><br />
</body>
</html>
alguna idea de como hacerlo?