Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9170867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:05:10+00:00 2026-06-17T16:05:10+00:00

How to accurately get difference(in years) between two DateTime objects in Years? DateTime.Subtract() gives

  • 0

How to accurately get difference(in years) between two DateTime objects in “Years”?

DateTime.Subtract() gives difference in TimeSpan and the maximum denomination is Days.

So, if I would want to get accurately, the difference between Today and a day in 1988(say 29th March 1988), is there an “easier” way to get the accurate age of this person?

What I’ve tried is:

DateTime March291988 = DateTime.Parse("29/03/1988");
TimeSpan ts = DateTime.Now.Subtract(March291988);
int years = (ts.Days/365);

More importantly, the question is: How to convert from TimeSpan to DateTime.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:05:11+00:00Added an answer on June 17, 2026 at 4:05 pm

    I’m biased, but I’d use Noda Time:

    var date1 = new LocalDate(1988, 3, 29);
    var date2 = new LocalDate(2013, 1, 23); // See note below
    var years = Period.Between(date1, date2, PeriodUnits.Years).Years;
    

    Basically the BCL doesn’t provide a hugely easy way of working with things like this – you really don’t want a TimeSpan, because it’s not anchored to a specific start/end point. You can subtract one Year value from another and then adjust if it does the wrong thing, but it’s a bit icky.

    Now in your original code, you used DateTime.Now. In Noda Time, we treat a clock as a dependency, with SystemClock.Instance being the normal production implementation. An IClock doesn’t know about time zones – it just knows the current instant in time – so you have to say which time zone you’re interested in. For example:

    var today = clock.Now.InZone(zone).LocalDateTime.Date;
    

    I know this seems long-winded, but it’s isolating all the different conversions to make it all more explicit. (I may introduce a Date property on ZoneDateTime to reduce this slightly.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to ask what is the difference between geometry and geography using
As the title states, I want to get the difference (in seconds) between 2
I need to get the square root of a 210 digit number accurately, I
I'm programming in python on windows and would like to accurately measure the time
I'm trying to measure the time difference between 2 signals on the parallel port,
I already know the difference between MVP and MVC. Then also after going through
I need to be able to compute differences between two data/time values which represent
Is there any accurate way to get the real size of a svg element
I'm trying to get this accurate timer working on VS2008, on Windows XP (and
I hope I worded the title accurately enough but I typically use Java and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.