How to return a list of weekend dates between 2 dates

Viewed 5451

At the moment I have this code to return a table of all dates between 2 dates. How could I change this to have it only return the weekend dates. The purpose of this is to use the weekend dates to check against column headers in a DataGridView to "grey-out" the weekends. I hope that's clear.

static public List<string> GetDates(DateTime start_date, DateTime end_date)
{
    List<string> days_list = new List<string>();

    for (DateTime date = start_date; date <= end_date; date = date.AddDays(1))
    {
        days_list.Add(date.ToShortDateString());
    }

    return days_list;
}
3 Answers
Related