well hello there ! let us calculate the age based on date of birth!!
let us start by creating our table!
i created one table with the following fields! dob and age
that is it for the database! next thing is to now hide the age field and set it as not required as this will be updated in the background! we only want the date of birth field so that the user can enter when they were born!
click on the add page
$('#ctrl-fechanacimiento').on('change', function() {
// Obtener el valor de la fecha de nacimiento
var fechaNac = new Date($(this).val());
var fechaActual = new Date();
// Calcular la edad
var edad = fechaActual.getFullYear() - fechaNac.getFullYear();
// Ajustar la edad si aún no ha llegado el cumpleaños este año
if (fechaNac.getMonth() > fechaActual.getMonth() ||
(fechaNac.getMonth() === fechaActual.getMonth() &&
fechaNac.getDate() > fechaActual.getDate())) {
edad--;
}
// Actualizar el campo de edad
$('#ctrl-edad').val(edad);
});