<!DOCTYPE html>
<html>
<head>
<meta charset="iso-8859-1">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
</head>
<body>
<script>
var calday = "0";
var calmon = "0";
var calyear = "0";
var curday = "0";
var curmon = "0"
var curyear = "0";
$(function() {
$("#btnCalcular").click(function() {
calday = $("#diaInit").val();
calmon = $("#mesInit").val();
calyear = $("#annoInit").val();
curday = $("#diaFinal").val();
curmon = $("#mesFinal").val();
curyear = $("#annoFinal").val();
calage();
});
});
function isNum(arg)
{
var args = arg;
if (args == "" || args == null || args.length == 0)
{
return false;
}
args = args.toString();
for (var i = 0; i<args.length; i++)
{
if ((args.substring(i,i+1) < "0" || args.substring(i, i+1) > "9") && args.substring(i, i+1) != ".")
{
return false;
}
}
return true;
}
function checkday(aa)
{
var val = aa.value;
var valc = val.substring(0,1);
if(val.length>0 && val.length<3)
{
if(!isNum(val) || val == 0)
{
aa.value="";
}
else if( val < 1 || val > 31)
{
aa.value=valc;
}
}
else if(val.length>2)
{
val = val.substring(0, 2);
aa.value=val;
}
}
function checkmon(aa) {
var val = aa.value;
var valc = val.substring(0,1);
if(val.length>0 && val.length<3)
{
if(!isNum(val) || val == 0)
{
aa.value="";
}
else if(val < 1 || val > 12)
{
aa.value=valc;
}
}
else if(val.length>2)
{
val = val.substring(0, 2);
aa.value=val;
}
}
function checkyear(aa) {
var val = aa.value;
var valc = val.substring(0,(val.length-1));
if(val.length>0 && val.length<7)
{
if(!isNum(val) || val == 0)
{
aa.value=valc;
}
else if(val < 1 || val>275759)
{
aa.value="";
}
}
else if(val.length>4)
{
aa.value=valc;
}
}
function checkleapyear(datea) {
if(datea.getYear()%4 == 0)
{
if(datea.getYear()% 10 != 0)
{
return true;
}
else
{
if(datea.getYear()% 400 == 0)
return true;
else
return false;
}
}
return false;
}
function DaysInMonth(Y, M) {
with (new Date(Y, M, 1, 12)) {
setDate(-2);
return getDate();
}
}
function datediff(date1, date2) {
var y1 = date1.getFullYear(), m1 = date1.getMonth(), d1 = date1.getDate(),
y2 = date2.getFullYear(), m2 = date2.getMonth(), d2 = date2.getDate();
if (d1 < d2) {
m1--;
d1 += DaysInMonth(y2, m2);
}
if (m1 < m2) {
y1--;
m1 += 12;
}
return [y1 - y2, m1 - m2, d1 - d2];
}
function calage() {
html = "";
if(curday == "" || curmon=="" || curyear=="" || calday=="" || calmon=="" || calyear=="") {
alert("Por favor, rellena todos los campos y vuelve a calcular");
}
else {
var curd = new Date(curyear,curmon-1,curday);
var cald = new Date(calyear,calmon-1,calday);
var diff = Date.UTC(curyear,curmon-1,curday,0,0,0)- Date.UTC(calyear,calmon-1,calday,0,0,0);
var dife = datediff(curd,cald);
if(checkleapyear(cald)==true) {
// document.cir.val.value = dife[0]+" años, "+dife[1]+" meses, y "+dife[2]+" dÃas";
html += dife[0]+" años, "+dife[1]+" meses, y "+dife[2]+" días";
}else{
// document.cir.val.value = dife[0]+" años, "+dife[1]+" meses, y "+dife[2]+" dÃas";
html += dife[0]+" años, "+dife[1]+" meses, y "+dife[2]+" días";
}
var secleft = diff/1000/60;
var hrsleft = secleft/60;
var daysleft = hrsleft/24;
// document.cir.val1.value=daysleft+" dÃas";
html += "<br>"+daysleft+" dias en total";
var as = parseInt(calyear)+dife[0]+1;
}
$("#zonaShow").html(html);
}
calage();
</script>
<div id="zonaShow"></div>
<p> Día inicial: <input type="text" id="diaInit"></p>
<p> Mes inicial:
<select id="mesInit">
<option value=1>Enero</option>
<option value=2>Febrero</option>
<option value=3>Marzo</option>
<option value=4>Abril</option>
<option value=5>Mayo</option>
<option value=6>Junio</option>
<option value=7>Julio</option>
<option value=8>Agosto</option>
<option value=9>Septiembre</option>
<option value=10>Octubre</option>
<option value=11>Noviembre</option>
<option value=12>Diciembre</option>
</select>
</p>
<p> Año inicial: <input type="text" id="annoInit"></p>
<hr>
<p> Día Final: <input type="text" id="diaFinal"></p>
<p> Mes Final:
<select id="mesFinal">
<option value=1>Enero</option>
<option value=2>Febrero</option>
<option value=3>Marzo</option>
<option value=4>Abril</option>
<option value=5>Mayo</option>
<option value=6>Junio</option>
<option value=7>Julio</option>
<option value=8>Agosto</option>
<option value=9>Septiembre</option>
<option value=10>Octubre</option>
<option value=11>Noviembre</option>
<option value=12>Diciembre</option>
</select>
</p>
<p> Año Final: <input type="text" id="annoFinal"></p>
<p><input type="button" id="btnCalcular" value="Calcular"></p>
</body>
</html>
Obtener distancia entre fechas
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario