When you want number of Thursdays or any other week day between two dates, there is no direct function in .NET. To fill the gap, I have written the following function that gives the count of a weekday between two given dates. This function is constructed without using iteration/loop statements.
public static int findWeekCount(DateTime startDate, DateTime toDate, DayOfWeek Week)
{
int _daysBetweenDates = (toDate - startDate).Days;
int _adjustingDays = (7 + (int)Week - (int)startDate.DayOfWeek) % 7;
int _oddDays = _daysBetweenDates % 7;
int _completeWeekTurns = (_daysBetweenDates) / 7;
int _addTurns = _oddDays >= _adjustingDays ? 1 : 0;
return _completeWeekTurns + _addTurns;
}
Usage:
DateTime sDate = new DateTime(2011, 09, 1);
DateTime eDate = new DateTime(2011, 11, 30);
DayOfWeek fWeek = DayOfWeek.Monday;
int totCount = findWeekCount(sDate, eDate, fWeek);
MessageBox.Show(totCount.ToString());
Hope this is useful. Any alternative is highly appreciated.