How to Find Number of Days for provided date range?

 Posted by Bhakti on 11/15/2009 | Category: C# Interview questions | Views: 4325

Code extract :

TimeSpan DayDifference = Convert.ToDateTime("2009-1-7").Subtract(Convert.ToDateTime("2009-1-1"));

To find the difference of the days, here we have used Subtract method. The Subtract method does not take start date into consideration. Hence, to get the exact number of days for the date range we need to add one more day to the result.

Response.Write("Number of Days : " + DayDifference.Days+1);

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response