valEdad.js 6.39 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
//Convertir DOB to Age
window.onload= init;


function init(){
    contarEdad();
    //fechaFormat();
}


function contarEdad() {
    let today = new Date();
    let dob = document.getElementById("dob").value;
    let current_datetime = new Date(dob);
    let month = current_datetime.getMonth();
    let day = current_datetime.getDate();
    let formatted_date = current_datetime.getDate() + "/" + (current_datetime.getMonth() + 1)  + "/" + current_datetime.getFullYear();
    //console.log(formatted_date); ver Fecha del form en formato dd/mm/yyy
    let date2=new Date(dob);
    let pattern = /^\d{1,2}\/\d{1,2}\/\d{4}$/; //Regex to validate date format (dd/mm/yyyy)
    let age = today.getFullYear() - current_datetime.getFullYear();

    if (pattern.test(formatted_date)) {
       if (today.getMonth() < month || (today.getMonth() == month && today.getDate() < day))
       {
         age--;
        }  
   //     console.log(age); ver edad
        let anio = document.getElementById("edad").innerHTML=age+" años";
    } else {
        alert("Invalid date format. Please Input in (dd/mm/yyyy) format!");
    }

/*
function fechaFormat(){

    //EXPERIENCIA

   let fechaInicioExp = document.getElementById("fechaInicioExp2").value;
   let fie =new Date(fechaInicioExp);
 //  let formatted_fie = fie.getDate() + "/" + (fie.getMonth() + 1)  + "/" + fie.getFullYear();
   
   let fechaFinExp = document.getElementById("fechaFinExp2").value;
   let ffe =new Date(fechaFinExp);
 //  let formatted_ffe = ffe.getDate() + "/" + (ffe.getMonth() + 1)  + "/" + ffe.getFullYear();
   

     // Validacion de ceros Fecha inicio
    if(((fie.getMonth() + 1) < 10) && (fie.getDate() < 10) ){
    let formatted_fie = "0"+  fie.getDate() + "/0" + (fie.getMonth() + 1)  + "/" + fie.getFullYear();
    let mostrar1 = document.getElementById("fiemostrar").innerHTML = formatted_fie;
    console.log(mostrar1);
    }else{
        if((fie.getMonth() + 1) < 10){
            let formatted_fie = fie.getDate() + "/0" + (fie.getMonth() + 1)  + "/" + fie.getFullYear();
             mostrar1 = document.getElementById("fiemostrar").innerHTML = formatted_fie;
             console.log(mostrar1);
        }else{
            if(fie.getDate() < 10){
                let formatted_fie ="0"+ fie.getDate() + "/" + (fie.getMonth() + 1)  + "/" + fie.getFullYear();
                 mostrar1 = document.getElementById("fiemostrar").innerHTML = formatted_fie;
                 console.log(mostrar1);
            }else{
                let formatted_fie = fie.getDate() + "/" + (fie.getMonth() + 1)  + "/" + fie.getFullYear();
                 mostrar1 = document.getElementById("fiemostrar2").innerHTML = formatted_fie;
                 console.log(mostrar1);
            }
        }
    }
    


   // Validacion de ceros Fecha fin
   if(((ffe.getMonth() + 1) < 10) && (ffe.getDate() < 10) ){
    let formatted_ffe = "0"+  ffe.getDate() + "/0" + (ffe.getMonth() + 1)  + "/" + ffe.getFullYear();
    let mostrar2 = document.getElementById("ffemostrar").innerHTML = formatted_ffe;
    console.log(mostrar2);
    }else{
        if((ffe.getMonth() + 1) < 10){
            let formatted_ffe = ffe.getDate() + "/0" + (ffe.getMonth() + 1)  + "/" + ffe.getFullYear();
             mostrar2 = document.getElementById("ffemostrar").innerHTML = formatted_ffe;
             console.log(mostrar2);
        }else{
            if(ffe.getDate() < 10){
                let formatted_ffe ="0"+ ffe.getDate() + "/" + (ffe.getMonth() + 1)  + "/" + ffe.getFullYear();
                 mostrar2 = document.getElementById("ffemostrar").innerHTML = formatted_ffe;
                 console.log(mostrar2);
            }else{
                let formatted_ffe = ffe.getDate() + "/" + (ffe.getMonth() + 1)  + "/" + ffe.getFullYear();
                 mostrar2 = document.getElementById("ffemostrar").innerHTML = formatted_ffe;
                 console.log(mostrar2);
            }
        }
    }
    

   

     //ESTUDIOS//////////

   let fechaInicioEst = document.getElementById("fechaInicioEst").value;
   let fies =new Date(fechaInicioEst);
   let formatted_fies = fies.getDate() + "/" + (fies.getMonth() + 1)  + "/" + fies.getFullYear();
   
   let fechaFinEst = document.getElementById("fechaFinEst").value;
   let ffes =new Date(fechaFinEst);
   let formatted_ffes = ffes.getDate() + "/" + (ffes.getMonth() + 1)  + "/" + ffes.getFullYear();
   
   // Validacion de ceros Fecha fin
   if(((ffes.getMonth() + 1) < 10) && (ffes.getDate() < 10) ){
    let formatted_ffes = "0"+  ffes.getDate() + "/0" + (ffes.getMonth() + 1)  + "/" + ffes.getFullYear();
    let mostrar3 = document.getElementById("ffesmostrar").innerHTML = formatted_ffes;
    }else{
        if((ffes.getMonth() + 1) < 10){
            let formatted_ffes = ffes.getDate() + "/0" + (ffes.getMonth() + 1)  + "/" + ffes.getFullYear();
             mostrar3 = document.getElementById("ffesmostrar").innerHTML = formatted_ffes;
        }else{
            if(ffes.getDate() < 10){
                let formatted_ffes ="0"+ ffes.getDate() + "/" + (ffes.getMonth() + 1)  + "/" + ffes.getFullYear();
                 mostrar3 = document.getElementById("ffesmostrar").innerHTML = formatted_ffes;
            }else{
                let formatted_ffes = ffes.getDate() + "/" + (ffes.getMonth() + 1)  + "/" + ffes.getFullYear();
                mostrar3 = document.getElementById("ffesmostrar").innerHTML = formatted_ffes;
            }
        }
    }
   

    // Validacion de ceros Fecha inicio
   if(((fies.getMonth() + 1) < 10) && (fies.getDate() < 10) ){
    let formatted_fies = "0"+  fies.getDate() + "/0" + (fies.getMonth() + 1)  + "/" + fies.getFullYear();
    let mostrar4 = document.getElementById("fiesmostrar").innerHTML = formatted_fies;
    }else{
        if((fies.getMonth() + 1) < 10){
            let formatted_fies = fies.getDate() + "/0" + (fies.getMonth() + 1)  + "/" + fies.getFullYear();
             mostrar4 = document.getElementById("fiesmostrar").innerHTML = formatted_fies;
        }else{
            if(fies.getDate() < 10){
                let formatted_fies ="0"+ fies.getDate() + "/" + (fies.getMonth() + 1)  + "/" + fies.getFullYear();
                 mostrar4 = document.getElementById("fiesmostrar").innerHTML = formatted_fies;
            }else{
                let formatted_fies = fies.getDate() + "/" + (fies.getMonth() + 1)  + "/" + fies.getFullYear();
                 mostrar4 = document.getElementById("fiesmostrar").innerHTML = formatted_fies;
            }
        }
    }
}*/


    
  
}