Hi.
only takes one line.
(toDate - fromDate).Days
or
This can be easily accomplished using an object of Type "TimeSpan". For example: let's assume that we want to know the number of days between the max. and min. values for the DateTime Type and show it in a Console window, then I may write something like:
DateTime d1=DateTime.MinValue;
DateTime d2=DateTime.MaxValue;
TimeSpan span=d2-d1;
Console.WriteLine
( "There're {0} days between {1} and {2}" , span.TotalDays, d1.ToString(), d2.ToString() );
Note that I used the TotalDays property to get the number of days in between. This gets me the number of days putting in consideration the years with fraction days (years with 366 days). I could also use the property "Days" that would get me the value considering that all the years consist of 365 days only.
refer this link
http://r4r.co.in/c1/01/tutorial/csharp/Calculating%20Duration%20Between%20Two%20Dates%20in%20Years,%20Months%20and%20Days.shtml[
^]