<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="https://stackoverflow.com/questions/9/how-do-i-calculate-someones-age-in-c">How do I calculate someone&#39;s age in C#?</a>  </p>
</blockquote>



<p>Maybe this could be silly but and I don't have issues with my age but sometimes it is good to calculate the exact age of someone, I have introduced my birthdate in my profile (01/12/1975) "dd/mm/yyyy" and it calculated 33 and I'm 32 actually still, isn't it better to calculate the exact age? </p>

<p>Maybe</p>

<pre><code>DateTime dt1 = DateTime.Now;
TimeSpan dt2;
dt2 = dt1.Subtract(new DateTime(1975, 12, 01));
double year = dt2.TotalDays / 365;
</code></pre>

<p>The result of year is 32.77405678074</p>

<p>Could this code be OK?</p>

[{'answer_id': 18603, 'author': 'Kevin Crumley', 'author_id': 1818, 'author_profile': 'https://Stackoverflow.com/users/1818', 'pm_score': 1, 'selected': False, 'text': '<blockquote>\n  <p>Maybe this could be silly but and I don\'t have issues with my age but sometimes it is good to calculate the exact age of someone, I have introduced my birthdate in my profile (01/12/1975) "dd/mm/yyyy" and it calculated 33 and I\'m 32 actually still, doesn\'t it better to calculate the exact age?  </p>\n</blockquote>\n\n<p>My guess would be that this is a localization issue, though I don\'t know how it would happen, since (at least for me) the profile has you fill out your age in the format "YYYY/MM/DD".  But your birthday is one that reads as a valid date (January 12th) in traditional U.S. settings, so this is the area I\'d look into.  I was born in 1975, also, and my birthday is next month, and it\'s got my age right.</p>\n'}, {'answer_id': 18610, 'author': 'Kibbee', 'author_id': 1862, 'author_profile': 'https://Stackoverflow.com/users/1862', 'pm_score': 0, 'selected': False, 'text': '<p>Actually, because of leap years, your code would be off.  Since the timespan object has no TotalYears property the best way to get it would be this</p>\n\n<p>Pardon the VB.Net</p>\n\n<pre><code>Dim myAge AS Integer = DateTime.Now.year - BirthDate.year\nIf Birthdate.month &lt; DateTime.Now.Month _\nOrElse BirthDate.Month = DateTime.Now.Month AndAlso Birthdate.Day &lt; DateTime.Now.Day Then\nMyAge -= 1\nEND IF\n</code></pre>\n'}, {'answer_id': 18718, 'author': 'Wedge', 'author_id': 332, 'author_profile': 'https://Stackoverflow.com/users/332', 'pm_score': 1, 'selected': True, 'text': '<p>If you were born on January 12th 1975, you would be 33 years old today.</p>\n\n<p>If you were born on December 1st 1975, you would be 32 years old today.</p>\n\n<p>If you read the note by the birthday field when editing your profile you\'ll see it says "YYYY/MM/DD", I\'m sure it will try to interpret dates of other formats but it looks like it interprets MM/DD/YYYY (US standard dates) in preference to DD/MM/YYYY (European standard dates). The easy fix is to enter the date of your birthday according to the suggested input style.</p>\n'}, {'answer_id': 10765738, 'author': 'Devarajan.T', 'author_id': 1418924, 'author_profile': 'https://Stackoverflow.com/users/1418924', 'pm_score': 0, 'selected': False, 'text': '<pre><code>int ag1;\nstring st, ag;\nvoid agecal()\n{\n    st = TextBox4.Text;\n    DateTimeFormatInfo dtfi = new DateTimeFormatInfo();\n    dtfi.ShortDatePattern = "MM/dd/yyyy";\n    dtfi.DateSeparator = "/";\n    DateTime dt = Convert.ToDateTime(st, dtfi);\n    ag1 = int.Parse(dt.Year.ToString());\n    int years = DateTime.Now.Year - ag1;\n    ag = years.ToString();\n    TextBox3.Text = ag.ToString();\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/18584', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1130097/']