Deseo restar la hora de inicio y la hora fin para obtener las horas trabajadas.
Quiero hacer esto dinámicamente al momento que cambie de valor un input pero no encuentro como hacerlo mediante input tipos time, hay desde input tipo text pero no me funciona con time.
¿Cuál sería el formato correcto?
function Horas(i) {
var jornada1 = 0;
var jornada2 = 0;
var permiso = 0;
var Horatotal = 0;
var Entrada = moment(document.getElementById("fieldSeasiHoring" + i).value);
var Salidaalm = moment(document.getElementById("fieldSeasiSalalm" + i).value);
var Entrada = moment(document.getElementById("fieldSeasiEntalm" + i).value);
var Salida = moment(document.getElementById("fieldSeasiHorsal" + i).value);
var horasmañana = 0;
var horastarde = 0;
var horasfinales = 0;
alert(Entrada);
Horatotal = Salidaalm.diff(Entrada, 'hours', true);
alert(Horatotal);
}
<script src="http://momentjs.com/downloads/moment.js"></script>
<table class="table table-bordered " width="100%">
<thead>
<tr class="bg-success">
<th>Nombres y Apellidos</th>
<th>Descripción</th>
<th>Ingreso</th>
<th>Salida almuerzo</th>
<th>Ingreso almuerzo</th>
<th>Salida</th>
<th>Salida permiso</th>
<th>Ingreso permiso</th>
<th>Tipo</th>
<th>Total horas</th>
<th>Total horas cincuenta</th>
<th>Total horas cien</th>
</tr>
</thead>
<tbody>
<tr>
<input type="hidden" id="codigo0" name="codigo[]" value="CONT00001" class="form-control codigo" size="30" readonly="true">
<input type="hidden" id="cedula0" name="cedula[]" value="2147483647" class="form-control cedula" size="30" readonly="true">
<td><input type="text" id="nombre0" name="nombre[]" value="JOSE LUIS LOOR ANDRADE" class="form-control nombre" size="30" readonly="readonly"></td>
<td><input type="text" id="fieldSeasiDescri0" name="fieldSeasiDescri[]" class="form-control sueldo"></td>
<td><input type="time" id="fieldSeasiHoring0" name="fieldSeasiHoring[]" value="06:00" class="form-control bono" placeholder="hrs:mins" min="00:00" max="23:59" onblur="Horas(0)"></td>
<td><input type="time" id="fieldSeasiSalalm0" name="fieldSeasiSalalm[]" value="06:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59" onblur="Horas(0)"></td>
<td><input type="time" id="fieldSeasiEntalm0" name="fieldSeasiEntalm[]" value="06:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59" onblur="Horas(0)"></td>
<td><input type="time" id="fieldSeasiHorsal0" name="fieldSeasiHorsal[]" value="06:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59" onblur="Horas(0)"></td>
<td><input type="time" id="fieldSeasiEntper0" name="fieldSeasiEntper[]" value="00:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59"></td>
<td><input type="time" id="fieldSeasiSalper0" name="fieldSeasiSalper[]" value="00:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59"></td>
<td><input type="number" id="fieldSeasiTipoxx0" name="fieldSeasiTipoxx[]" value="30.50" class="form-control dtmensual"></td>
<td><input type="number" id="fieldSeasiTothor0" name="fieldSeasiTothor[]" value="0" class="form-control cdmensual" readonly="true"></td>
<td><input type="number" id="fieldSeasiTohoca0" name="fieldSeasiTohoca[]" class="form-control freserva" readonly="true"></td>
<td><input type="number" id="fieldSeasiTohocn0" name="fieldSeasiTohocn[]" class="form-control hextrascin" readonly="true"></td>
</tr>
<tr>
<input type="hidden" id="codigo1" name="codigo[]" value="CONT00002" class="form-control codigo" size="30" readonly="true">
<input type="hidden" id="cedula1" name="cedula[]" value="230005953" class="form-control cedula" size="30" readonly="true">
<td><input type="text" id="nombre1" name="nombre[]" value="MARCELA ESTEFANIA BONILLA BARRAGAN" class="form-control nombre" size="30" readonly="readonly"></td>
<td><input type="text" id="fieldSeasiDescri1" name="fieldSeasiDescri[]" class="form-control sueldo"></td>
<td><input type="time" id="fieldSeasiHoring1" name="fieldSeasiHoring[]" value="06:00" class="form-control bono" placeholder="hrs:mins" min="00:00" max="23:59" onblur="Horas(1)"></td>
<td><input type="time" id="fieldSeasiSalalm1" name="fieldSeasiSalalm[]" value="06:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59" onblur="Horas(1)"></td>
<td><input type="time" id="fieldSeasiEntalm1" name="fieldSeasiEntalm[]" value="06:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59" onblur="Horas(1)"></td>
<td><input type="time" id="fieldSeasiHorsal1" name="fieldSeasiHorsal[]" value="06:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59" onblur="Horas(1)"></td>
<td><input type="time" id="fieldSeasiEntper1" name="fieldSeasiEntper[]" value="00:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59"></td>
<td><input type="time" id="fieldSeasiSalper1" name="fieldSeasiSalper[]" value="00:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59"></td>
<td><input type="number" id="fieldSeasiTipoxx1" name="fieldSeasiTipoxx[]" value="30.50" class="form-control dtmensual"></td>
<td><input type="number" id="fieldSeasiTothor1" name="fieldSeasiTothor[]" value="0" class="form-control cdmensual" readonly="true"></td>
<td><input type="number" id="fieldSeasiTohoca1" name="fieldSeasiTohoca[]" class="form-control freserva" readonly="true"></td>
<td><input type="number" id="fieldSeasiTohocn1" name="fieldSeasiTohocn[]" class="form-control hextrascin" readonly="true"></td>
</tr>
<tr>
<input type="hidden" id="codigo2" name="codigo[]" value="CONT00003" class="form-control codigo" size="30" readonly="true">
<input type="hidden" id="cedula2" name="cedula[]" value="0" class="form-control cedula" size="30" readonly="true">
<td><input type="text" id="nombre2" name="nombre[]" value="" class="form-control nombre" size="30" readonly="readonly"></td>
<td><input type="text" id="fieldSeasiDescri2" name="fieldSeasiDescri[]" class="form-control sueldo"></td>
<td><input type="time" id="fieldSeasiHoring2" name="fieldSeasiHoring[]" value="06:00" class="form-control bono" placeholder="hrs:mins" min="00:00" max="23:59" onblur="Horas(2)"></td>
<td><input type="time" id="fieldSeasiSalalm2" name="fieldSeasiSalalm[]" value="06:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59" onblur="Horas(2)"></td>
<td><input type="time" id="fieldSeasiEntalm2" name="fieldSeasiEntalm[]" value="06:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59" onblur="Horas(2)"></td>
<td><input type="time" id="fieldSeasiHorsal2" name="fieldSeasiHorsal[]" value="06:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59" onblur="Horas(2)"></td>
<td><input type="time" id="fieldSeasiEntper2" name="fieldSeasiEntper[]" value="00:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59"></td>
<td><input type="time" id="fieldSeasiSalper2" name="fieldSeasiSalper[]" value="00:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59"></td>
<td><input type="number" id="fieldSeasiTipoxx2" name="fieldSeasiTipoxx[]" value="30.50" class="form-control dtmensual"></td>
<td><input type="number" id="fieldSeasiTothor2" name="fieldSeasiTothor[]" value="0" class="form-control cdmensual" readonly="true"></td>
<td><input type="number" id="fieldSeasiTohoca2" name="fieldSeasiTohoca[]" class="form-control freserva" readonly="true"></td>
<td><input type="number" id="fieldSeasiTohocn2" name="fieldSeasiTohocn[]" class="form-control hextrascin" readonly="true"></td>
</tr>
<tr>
<input type="hidden" id="codigo3" name="codigo[]" value="CONT00004" class="form-control codigo" size="30" readonly="true">
<input type="hidden" id="cedula3" name="cedula[]" value="1725369548" class="form-control cedula" size="30" readonly="true">
<td><input type="text" id="nombre3" name="nombre[]" value="PALADINES MERINO ANDREA CAROLINA" class="form-control nombre" size="30" readonly="readonly"></td>
<td><input type="text" id="fieldSeasiDescri3" name="fieldSeasiDescri[]" value="AUXILIAR CONTABLE" class="form-control sueldo"></td>
<td><input type="time" id="fieldSeasiHoring3" name="fieldSeasiHoring[]" value="06:00" class="form-control bono" placeholder="hrs:mins" min="00:00" max="23:59" onblur="Horas(3)"></td>
<td><input type="time" id="fieldSeasiSalalm3" name="fieldSeasiSalalm[]" value="06:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59" onblur="Horas(3)"></td>
<td><input type="time" id="fieldSeasiEntalm3" name="fieldSeasiEntalm[]" value="06:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59" onblur="Horas(3)"></td>
<td><input type="time" id="fieldSeasiHorsal3" name="fieldSeasiHorsal[]" value="06:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59" onblur="Horas(3)"></td>
<td><input type="time" id="fieldSeasiEntper3" name="fieldSeasiEntper[]" value="00:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59"></td>
<td><input type="time" id="fieldSeasiSalper3" name="fieldSeasiSalper[]" value="00:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59"></td>
<td><input type="number" id="fieldSeasiTipoxx3" name="fieldSeasiTipoxx[]" value="30.50" class="form-control dtmensual"></td>
<td><input type="number" id="fieldSeasiTothor3" name="fieldSeasiTothor[]" value="0" class="form-control cdmensual" readonly="true"></td>
<td><input type="number" id="fieldSeasiTohoca3" name="fieldSeasiTohoca[]" class="form-control freserva" readonly="true"></td>
<td><input type="number" id="fieldSeasiTohocn3" name="fieldSeasiTohocn[]" class="form-control hextrascin" readonly="true"></td>
</tr>
<tr>
<input type="hidden" id="codigo4" name="codigo[]" value="CONT00005" class="form-control codigo" size="30" readonly="true">
<input type="hidden" id="cedula4" name="cedula[]" value="2147483647" class="form-control cedula" size="30" readonly="true">
<td><input type="text" id="nombre4" name="nombre[]" value="MESIAS ROSADO CARLA SOFIA" class="form-control nombre" size="30" readonly="readonly"></td>
<td><input type="text" id="fieldSeasiDescri4" name="fieldSeasiDescri[]" value="AUXILIAR CONTABLE" class="form-control sueldo"></td>
<td><input type="time" id="fieldSeasiHoring4" name="fieldSeasiHoring[]" value="06:00" class="form-control bono" placeholder="hrs:mins" min="00:00" max="23:59" onblur="Horas(4)"></td>
<td><input type="time" id="fieldSeasiSalalm4" name="fieldSeasiSalalm[]" value="06:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59" onblur="Horas(4)"></td>
<td><input type="time" id="fieldSeasiEntalm4" name="fieldSeasiEntalm[]" value="06:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59" onblur="Horas(4)"></td>
<td><input type="time" id="fieldSeasiHorsal4" name="fieldSeasiHorsal[]" value="06:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59" onblur="Horas(4)"></td>
<td><input type="time" id="fieldSeasiEntper4" name="fieldSeasiEntper[]" value="00:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59"></td>
<td><input type="time" id="fieldSeasiSalper4" name="fieldSeasiSalper[]" value="00:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59"></td>
<td><input type="number" id="fieldSeasiTipoxx4" name="fieldSeasiTipoxx[]" value="30.50" class="form-control dtmensual"></td>
<td><input type="number" id="fieldSeasiTothor4" name="fieldSeasiTothor[]" value="0" class="form-control cdmensual" readonly="true"></td>
<td><input type="number" id="fieldSeasiTohoca4" name="fieldSeasiTohoca[]" class="form-control freserva" readonly="true"></td>
<td><input type="number" id="fieldSeasiTohocn4" name="fieldSeasiTohocn[]" class="form-control hextrascin" readonly="true"></td>
</tr>
<tr>
<input type="hidden" id="codigo5" name="codigo[]" value="CONT00006" class="form-control codigo" size="30" readonly="true">
<input type="hidden" id="cedula5" name="cedula[]" value="2147483647" class="form-control cedula" size="30" readonly="true">
<td><input type="text" id="nombre5" name="nombre[]" value="ROMAN ESTRADA JAVIER ALEXANDER" class="form-control nombre" size="30" readonly="readonly"></td>
<td><input type="text" id="fieldSeasiDescri5" name="fieldSeasiDescri[]" value="JEFE DE CAMPO" class="form-control sueldo"></td>
<td><input type="time" id="fieldSeasiHoring5" name="fieldSeasiHoring[]" value="06:00" class="form-control bono" placeholder="hrs:mins" min="00:00" max="23:59" onblur="Horas(5)"></td>
<td><input type="time" id="fieldSeasiSalalm5" name="fieldSeasiSalalm[]" value="06:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59" onblur="Horas(5)"></td>
<td><input type="time" id="fieldSeasiEntalm5" name="fieldSeasiEntalm[]" value="06:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59" onblur="Horas(5)"></td>
<td><input type="time" id="fieldSeasiHorsal5" name="fieldSeasiHorsal[]" value="06:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59" onblur="Horas(5)"></td>
<td><input type="time" id="fieldSeasiEntper5" name="fieldSeasiEntper[]" value="00:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59"></td>
<td><input type="time" id="fieldSeasiSalper5" name="fieldSeasiSalper[]" value="00:00" class="form-control " placeholder="hrs:mins" min="00:00" max="23:59"></td>
<td><input type="number" id="fieldSeasiTipoxx5" name="fieldSeasiTipoxx[]" value="25.00" class="form-control dtmensual"></td>
<td><input type="number" id="fieldSeasiTothor5" name="fieldSeasiTothor[]" value="0" class="form-control cdmensual" readonly="true"></td>
<td><input type="number" id="fieldSeasiTohoca5" name="fieldSeasiTohoca[]" class="form-control freserva" readonly="true"></td>
<td><input type="number" id="fieldSeasiTohocn5" name="fieldSeasiTohocn[]" class="form-control hextrascin" readonly="true"></td>
</tr>
</tbody>
</table>