Day Occurrence within date range? RRS feed

  • Question

  • Hello,

           I have two dates say ‘02/21/2009’ and ‘03/21/2009’. Now I want to know how many times the day Sunday occurs within this range. Code snippet would be helpful.


    Wednesday, April 8, 2009 12:52 PM


  • Hello Friends,

               I wrote this Method to find the number of occurrence of a particular day within a date range.


    private int FindDayInDates(string dayToFind, DateTime lowerDate, DateTime upperDate)


    int dayCount = 0;

           while (lowerDate <= upperDate)


                  if (dayToFind.Equals(lowerDate.DayOfWeek.ToString()))


                   lowerDate = lowerDate.AddDays(1);


           return dayCount


    • Marked as answer by Imran Amodi Wednesday, April 8, 2009 2:18 PM
    Wednesday, April 8, 2009 2:16 PM