![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
15/02/2002, 16:05
|
![Avatar de Kaopectate](http://static.forosdelweb.com/customavatars/avatar14704_1.gif) | Colaborador | | Fecha de Ingreso: diciembre-2001 Ubicación: Curaçao (Antillas Holandesas)
Mensajes: 3.179
Antigüedad: 23 años, 1 mes Puntos: 38 | |
Re: Sumar Dias Versión modificada para que el resultado quede en el formato dd/mm/aa:
<html>
<head>
<script language="JavaScript">
var aFinMes = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
function finMes(nMes, nAno){
return aFinMes[nMes - 1] + ((nAno % 4) == 0? 1: 0);
}
function padNmb(nStr, nLen){
var sRes = String(nStr);
var sCeros = "0000000000";
return sCeros.substr(0, nLen - sRes.length) + sRes;
}
function addToDate(sFec0, sInc){
var nDia = Number(sFec0.substr(0, 2));
var nMes = Number(sFec0.substr(3, 2));
var nAno = Number(sFec0.substr(6, 4));
nDia += Number(sInc);
while (nDia > finMes(nMes, nAno)){
nDia -= finMes(nMes, nAno);
nMes += 1;
if (nMes == 13){
nMes = 1;
nAno += 1;
}
}
return padNmb(nDia, 2) + "/" + padNmb(nMes, 2) + "/" + padNmb(nAno, 4);
}
function recalcF1(){
with (document.formulario){
fecha1.value = addToDate(fecha0.value, increm.value);
}
}
</script>
</head>
<body>
<form name="formulario">
<table>
<tr>
<td align="right">
Coloque una fecha válida (dd/mm/aaaa):
</td>
<td>
<input type="text" name="fecha0" size="10">
</td>
</tr>
<tr>
<td align="right">
Incremento:
</td>
<td>
<input type="text" name="increm" size="3">
</td>
</tr>
<tr>
<td align="right">
Resultado (dd/mm/aaaa):
</td>
<td>
<input type="text" name="fecha1" disabled size="10">
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="button" onclick="recalcF1()" value="Calcular">
</td>
</tr>
</table>
</form>
</body>
</html>
Avísame si no te funciona. |