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.
Related Contents:
- Is DateTime.Now the best way to measure a function’s performance? [closed]
- How do I get the last day of a month?
- How to truncate milliseconds off of a .NET DateTime
- Convert UTC/GMT time to local time
- Get Month name from month number
- How do I represent a time only value in .NET?
- How do I get the AM/PM value from a DateTime?
- Parse string to DateTime in C#
- String was not recognized as a valid DateTime ” format dd/MM/yyyy”
- Creating a DateTime in a specific Time Zone in c#
- How to convert DateTime? to DateTime
- How to create a .NET DateTime from ISO 8601 format
- How to compare DateTime in C#?
- Get the previous month’s first and last day dates in c#
- Difference between System.DateTime.Now and System.DateTime.Today
- calculating the difference in months between two dates
- Measuring code execution time
- Get timezone from DateTime
- How can I format DateTime to web UTC format?
- Getting Date or Time only from a DateTime Object
- DateTime.Compare how to check if a date is less than 30 days old?
- Java System.currentTimeMillis() equivalent in C#
- Implementing a non-terrestrial calendar
- Convert month int to month name
- How to know if a DateTime is between a DateRange in C#
- How to list all month names, e.g. for a combo?
- How to set only time part of a DateTime variable in C# [duplicate]
- What does “DateTime?” mean in C#?
- datetime to string with time zone
- How to convert Javascript datetime to C# datetime?
- No overload for method ‘ToString” takes 1 arguments when casting date
- Environment.TickCount vs DateTime.Now
- How does DateTime.ToUniversalTime() work?
- Convert YYYYMMDD string date to a datetime value [duplicate]
- DateTime.Parse(“2012-09-30T23:00:00.0000000Z”) always converts to DateTimeKind.Local
- How does DateTime.Now.Ticks exactly work?
- Is there a better way to trim a DateTime to a specific precision?
- How to set a time zone (or a Kind) of a DateTime value?
- Parse DateTime with time zone of form PST/CEST/UTC/etc
- Convert DateTime to long and also the other way around
- How to convert DateTime of type DateTimeKind.Unspecified to DateTime.Kind.Utc in C# (.NET)
- Why is DateTime.Now a property and not a method?
- Convert Date from Persian to Gregorian
- What does a single quote inside a C# date time format mean?
- Date comparison – How to check if 20 minutes have passed?
- Can DateTime tear in a 64 bit environment?
- How to get difference between two dates in Year/Month/Week/Day?
- .NET DateTime to SqlDateTime Conversion
- How to compare time part of datetime
- Format DateTime.Now to yyyy-mm-dd