I want to calculate the age based on birth date and it should rounded to the nearest i.e. 19/03/1988 would be resultant into 26 and 19/09/1988 to 25.
Below is the current implementation.
var ts = DateTime.Now - dtBirthdate;
var age = ts.Days / 365;
I want to calculate the age based on birth date and it should rounded to the nearest i.e. 19/03/1988 would be resultant into 26 and 19/09/1988 to 25.
Below is the current implementation.
var ts = DateTime.Now - dtBirthdate;
var age = ts.Days / 365;
 
    
     
    
    The problem with your current implementation is integer division. If you replace with a double, it should work better:
var ts = DateTime.Now - new DateTime(1988, 3, 19);
var age = Math.Round(ts.Days / 365.0);
