Ver Mensaje Individual
  #3 (permalink)  
Antiguo 11/03/2012, 13:21
karlos_11
 
Fecha de Ingreso: marzo-2012
Mensajes: 2
Antigüedad: 12 años, 2 meses
Puntos: 0
Respuesta: restar fechas

gracias por el ejemplo.......los mezcle y pude tener el resultado que buscaba
<html>
<head>
<script language="JavaScript">
function mueveReloj(){
momentoActual = new Date()
hora = momentoActual.getHours()
minuto = momentoActual.getMinutes()
segundo = momentoActual.getSeconds()

horaImprimible = hora + " : " + minuto + " : " + segundo

document.info_repo.reloj1.value = horaImprimible

setTimeout("mueveReloj()",1000)
}
</script>
<script>
function padNmb(nStr, nLen){
var sRes = String(nStr);
var sCeros = "0000000000";
return sCeros.substr(0, nLen - sRes.length) + sRes;
}

function stringToSeconds(tiempo){
var sep1 = tiempo.indexOf(":");
var sep2 = tiempo.lastIndexOf(":");
var hor = tiempo.substr(0, sep1);
var min = tiempo.substr(sep1 + 1, sep2 - sep1 - 1);
var sec = tiempo.substr(sep2 + 1);
return (Number(sec) + (Number(min) * 60) + (Number(hor) * 3600));
}

function secondsToTime(secs){
var hor = Math.floor(secs / 3600);
var min = Math.floor((secs - (hor * 3600)) / 60);
var sec = secs - (hor * 3600) - (min * 60);
return padNmb(hor, 2) + ":" + padNmb(min, 2) + ":" + padNmb(sec, 2);
}

function substractTimes(h1, h2){
var secs1 = stringToSeconds(h1);
var secs2 = stringToSeconds(h2);
var secsDif = secs1 - secs2;
return secondsToTime(secsDif);
}
function copiar(fuente, destino) {
document.getElementById(destino).value= document.getElementById(fuente).value;
}
function desa(){
document.info_repo.b1.disabled=true;
document.info_repo.b2.disabled=false;
}
function desa1(){
document.info_repo.b2.disabled=true;
}
function calcT3(){
with (document.info_repo)
h3.value = substractTimes(h2.value, h1.value);
}
</script>
<head >
<body onload="mueveReloj()">
<form name="info_repo">
<label>Hora</label>
<input type="text" name="reloj1" id="hora1"/>
<hr>
<input type="button" name="b1" value="hora inicio" onclick="copiar('hora1','hora2')+desa(this)"/>
<input type="text" name="h1" id="hora2"/>
<hr>
<input type="button" name="b2" value="hora termino" disabled="true" onclick="copiar('hora1','hora3')+desa1(this)"/>
<input type="text" name="h2" id="hora3"/>
<hr>
<input type="button" value="resta" onclick="calcT3()"/>
<input type="text" name="h3"/>
</form>
</body>
</html>

dejo el ejemplo terminado ...
atte.karlos_11