.Net is really great environment, a lot of functionality has already been implemented  and ready to use. Its just one dot away. Here  for example, you don’t need to implement anything to find the day of date just use DayOfWeek function.


private Int32 NoOfDates(DateTime StartDate, DateTime EndDate)
{
//difference between two dates
TimeSpan diff= EndDate- StartDate;
//Correct number of days by adding 1
int TDates = Diff.Days + 1;

int NoOfSundays = 0;

for (int i = 1; i <= TDates ; i++)
{
//Instead Sunday we can use any day of week exmp. DayOfWeek.Friday
if (StartDate.DayOfWeek == DayOfWeek.Sunday)
{
NoOfSundays++;
}
//Add one day to startdate to see if next day is Sunday
StartDate= StartDate.AddDays(1);
}

return NoOfSundays;
}