9
Reply

Get years from System.TimeSpan object

sojan m y

sojan m y

Jan 19 2011 7:52 AM
20.6k

I have a line of code given below where dt1 and dt2 are DateTime objects and I want to calculate or get number of years using ts TimeSpan object.

TimeSpan ts = dt1.Date - dt2.Date;

Example: dt1 has 1/19/2011 12:00:00 AM and dt2 has 1/19/1980 12:00:00 AM. ts gets the difference in days.I need to calculate number of years using ts.

Please suggest if any solution.

Thanks.


Answers (9)