Ver Mensaje Individual
  #2 (permalink)  
Antiguo 23/01/2008, 07:26
Avatar de agressor
agressor
 
Fecha de Ingreso: noviembre-2007
Ubicación: Knocking the Death Door..
Mensajes: 368
Antigüedad: 17 años, 2 meses
Puntos: 3
Re: restar fechas

Aqui te lo explican mas detallado.. espero le entiendas cualquier ocas me avisas..


http://www.webestilo.com/foros/mensa...o=11&msg=39495

tambien puedes revisar las FAQS del foro.. aqui esta este codigo.. espero te sirva..!

(Kaopectate creador)

Aqui..

<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] + (((nMes == 2) && (nAno % 4) == 0)? 1: 0);
}

function padNmb(nStr, nLen, sChr){
var sRes = String(nStr);
for (var i = 0; i < nLen - String(nStr).length; i++)
sRes = sChr + sRes;
return sRes;
}

function makeDateFormat(nDay, nMonth, nYear){
var sRes;
sRes = padNmb(nDay, 2, "0") + "/" + padNmb(nMonth, 2, "0") + "/" + padNmb(nYear, 4, "0");
return sRes;
}

function incDate(sFec0){
var nDia = parseInt(sFec0.substr(0, 2), 10);
var nMes = parseInt(sFec0.substr(3, 2), 10);
var nAno = parseInt(sFec0.substr(6, 4), 10);
nDia += 1;
if (nDia > finMes(nMes, nAno)){
nDia = 1;
nMes += 1;
if (nMes == 13){
nMes = 1;
nAno += 1;
}
}
return makeDateFormat(nDia, nMes, nAno);
}

function decDate(sFec0){
var nDia = Number(sFec0.substr(0, 2));
var nMes = Number(sFec0.substr(3, 2));
var nAno = Number(sFec0.substr(6, 4));
nDia -= 1;
if (nDia == 0){
nMes -= 1;
if (nMes == 0){
nMes = 12;
nAno -= 1;
}
nDia = finMes(nMes, nAno);
}
return makeDateFormat(nDia, nMes, nAno);
}

function addToDate(sFec0, sInc){
var nInc = Math.abs(parseInt(sInc));
var sRes = sFec0;
if (parseInt(sInc) >= 0)
for (var i = 0; i < nInc; i++) sRes = incDate(sRes);
else
for (var i = 0; i < nInc; i++) sRes = decDate(sRes);
return sRes;
}

function recalcF1(){
with (document.formulario){
fecha1.value = addToDate(fecha0.value, increm.value);
}
}

</script>
</head>
<body>
<form name="formulario">
<table>
<tr>
<td align="right">
Fecha (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>


SALU2..!!
__________________
Somos lo que nosotros queremos ni mas ni menos..
No hay dia mas perdido que aquel en que no hemos reido..
La vida es tal y como debe ser...
Nadie vivira por ti...