9
Answers

Get years from System.TimeSpan object

sojan m y

sojan m y

14y
20.6k
1

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)