Home

Published

- 1 min read

get all sundays between two dates c#

img of get all sundays between two dates c#

The solution for this is noted below

get all sundays between two dates c#

Solution

   IEnumerable<DateTime> GetDaysBetween(DateTime start, DateTime end)
{
    for (DateTime i = start; i < end; i = i.AddDays(1))
    {
        yield return i;
    }
}

var weekends = GetDaysBetween(DateTime.Today, DateTime.Today.AddDays(365))
    .Where(d => d.DayOfWeek == DayOfWeek.Saturday && d.DayOfWeek == DayOfWeek.Sunday);

Try other methods by searching on the site. That is if this doesn’t work