I need to calculate a person's age from their birth date, but I am doing a poor calculation, I give you an example.
Pepito was born on December 17, 1997, at this moment Pepito is 19 years old, but to me in the calculation he shows me as if he were 20 years old.
My code is as follows:
//FECHA NACIMIENTO EN LA BASE DE DATOS
[Display(Name = "Fecha Nacimiento")]
[DataType(DataType.Date)]
public DateTime fecha_nacimiento { get; set; }
//CALCULO DE LA EDAD
[NotMapped]
[Display(Name = "Edad")]
public int edad { get { return DateTime.Now.Year - fecha_nacimiento.Year; } }
In my database the date is as follows:
1997-12-17 00: 00: 00.000