Ver Mensaje Individual
  #2 (permalink)  
Antiguo 04/05/2015, 03:15
erpakillo
 
Fecha de Ingreso: diciembre-2014
Mensajes: 13
Antigüedad: 9 años, 5 meses
Puntos: 0
Respuesta: Problema con cálculo de tiempo

Me autosoluciono. La solucion es hacer que el resultado lo muestre solo en horas, así hace la operación bien. Así quedaría el código de javascrip(Por si a alguien le sirve):

<script type="text/javascript">
function interval_date()
{
var fecha1 = document.getElementById("fecha1").value;
var hora1 = document.getElementById("hora1").value;
var fecha2= document.getElementById("fecha2").value;
var hora2 = document.getElementById("hora2").value;
var fecha3 = document.getElementById("fecha3").value;
var hora3 = document.getElementById("hora3").value;
var fecha4= document.getElementById("fecha4").value;
var hora4 = document.getElementById("hora4").value;
var resultadototal = document.getElementById("resultado").value;
var resultadototal2 = document.getElementById("resultado2").value;


var totaltotal = Date.parse(resultadototal + " " + resultadototal2) / 1000;
var init = Date.parse(fecha1 + " " + hora1) / 1000;
var finish = Date.parse(fecha2 + " " + hora2) / 1000;
var init2 = Date.parse(fecha3 + " " + hora3) / 1000;
var finish2 = Date.parse(fecha4 + " " + hora4) / 1000;
//formateamos las fechas a segundos tipo 1374998435
diferencia = parseInt(finish) - parseInt(init);
diferencia2 = parseInt(finish2) - parseInt(init2);


//comprobamos el tiempo que ha pasado en segundos entre las dos fechas
//floor devuelve el número entero anterior, si es 5.7 devuelve 5
if(diferencia > 0 && diferencia ){
tiempo =Math.floor(diferencia/3600);
}else{
tiempo = "Error";
}
//Segunda Tabla
if(diferencia2 > 0 && diferencia2 ){
tiempo2 =Math.floor(diferencia2/3600);
}else{
tiempo2 = "Error";
}

//Ahora se escribe el resultado en otro input.

document.getElementById("resultadototal").value=pa rseFloat(tiempo)-parseFloat(tiempo2);

document.getElementById("resultado").value = tiempo;
document.getElementById("resultado2").value = tiempo2;
document.getElementById("resultadototal").value = diferenciatotal;

}
</script>