C# – How do I calculate someone’s age based on a DateTime type birthday?


An easy to understand and simple solution.

// Save today's date.
var today = DateTime.Today;

// Calculate the age.
var age = today.Year - birthdate.Year;

// Go back to the year in which the person was born in case of a leap year
if (birthdate.Date > today.AddYears(-age)) age--;

However, this assumes you are looking for the western idea of the age and not using East Asian reckoning.


What Is a Web Application?
Web applications are programs allowing better communication between businesses and their customers. …
How much can I earn from Google Adsense?
Google AdSense is a Google program that allows publishers to monetize their …

Blog at WordPress.com.

%d blogeri kao ovaj: