.comment-link {margin-left:.6em;}
Gert .Net
[GertDotNet]
20040108
 
Calculate an Age using C#
Looks like there is no default library function to calculate the age in years of a certain person. This is what I use starting today:


public static int CalcAgeInYears(DateTime birthDate, DateTime now) {
int result = now.Year - birthDate.Year;
if (now.DayOfYear > birthDate.DayOfYear) {
return result;
} else {
return result - 1;
}
}

Comments: Een reactie plaatsen


Links to this post:

Een koppeling maken


Powered by Blogger