Bring .Age() to Class DateTime - by Real McCoy

Status : 

  Deferred<br /><br />
		The product team has reviewed this issue and has deferred it for consideration at a later time.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 799948 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 9/8/2013 3:28:08 AM
Access Restriction Public


After reading this I have a headache.

Wouldn't it make sense if you guys just implement Age() method in DateTime class? Something like:

public int Age()
    var today = DateTime.Now;
    return ((today.Year - this.Year) * 372 + (today.Month - this.Month) * 31 + (today.Day - this.Day)) / 372;

This answer has the explanation why it would work:


public int Age()
    var today = DateTime.UtcNow;
    return today.Year - this.Year - ((today.Month > this.Month || (today.Month == this.Month && today.Day >= this.Day)) ? 0 : 1);

Or even a low level implementation. I guess Excel and other teams at Microsoft must have some elegant low-level implementations ready for calculating age from given date.
Sign in to post a comment.
Posted by Real McCoy on 4/7/2014 at 2:50 PM
@Programmerman, while I agree with you that TimeSpan is more suitable place for Age() (or ElapsedYears()), the locales can be managed via .NET Framework too.

For a record, there are 49 calendars:

and 186 locales: (most of them are redundant).

It would be an amazing achievement if .NET framework support all of them natively.
Posted by Tarek [MSFT] on 10/2/2013 at 2:56 PM
Thanks for your submission. we'll look at this issue in the future releases and consider all feedbacks around this issue like which class should have such functionality (DateTime, Calendar...etc.), should be extension method released out of band or it have a blog for it.
Posted by Programmerman on 9/16/2013 at 3:38 PM
Actually, I'm not sure Age makes sense in DateTime for the general case. If you find it's that common in your code, write your own extension method. Too many locales have their own calendars with their own concept of a year that this function doesn't really make a lot of sense for the global framework.
Posted by Programmerman on 9/16/2013 at 3:32 PM
I'm not sure Age() in DateTime makes sense, but you could make an argument for Years/TotalYears in TimeSpan. Age is a time span, not a date.
Posted by Microsoft on 9/11/2013 at 4:08 AM
Thank you for submitting feedback on Visual Studio and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by Microsoft on 9/8/2013 at 3:52 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(