jQWidgets Forums

This topic contains 1 reply, has 1 voice, and was last updated by  eabarca 11 years ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Caculate age Posts
  • Caculate age #57117

    eabarca
    Participant

    Hi everybody, i want to get age from jqxDateTimeInput and set to jqxInput(must be readonly). I also want to use my functions.php file, but i dont know how. I thought using source(functions.php?date=) inside jqxInput but this element should be fired when i pick up a date. Any idea or help? Thanks.-

    Caculate age #57476

    eabarca
    Participant

    If someone need to calculate it, this is the code im using:

    function esBiciesto(anio){
    	if ((anio % 4 == 0 && anio % 100 != 0) || (anio % 4 == 0 && anio % 100 == 0 && anio % 400 == 0)) {
    		return 1;
    	}else{
    		return 0;
    	}
    }
    
    function cantidadDiasPorMes(anio, mes) {
    	var arrayDiaMes = [[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]];
    	return arrayDiaMes[esBiciesto(anio)][mes - 1];
    }
    
    function calcularEdad(fecha){
    
    	//fecha HOY
    	var hoy = new Date();
    	var mesHoy = hoy.getMonth() + 1;
    	var diaHoy = hoy.getDate();
    	var anioHoy = hoy.getFullYear();
    	
    	//fecha SELECCIONADA
    	var mesFecha = fecha.getMonth() + 1;
    	var diaFecha = fecha.getDate();
    	var anioFecha = fecha.getFullYear();
    	
    	var anios = anioHoy - anioFecha;
    	var meses = mesHoy - mesFecha;;
    	var dias = diaHoy - diaFecha;;
    	if (dias < 0) {
    		meses--;
    		if ((mesFecha - 1) == 0) {
    			dias += cantidadDiasPorMes(anioFecha, 12);
    		} else {
    			dias += cantidadDiasPorMes(anioFecha, mesFecha - 1);
    		}
    	}
    	if (meses < 0) {
    		meses += 12;
    		anios--;
    	}
    	return anios;
    }

    And:

    $("#FechaNacimiento").on('close', function(event){
    		$("#Edad").val(calcularEdad($("#FechaNacimiento").jqxDateTimeInput('getDate')));
    });
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.