Answers for "Get all dates of every monday between two dates in c#"

C#
0

Get all dates of every monday between two dates in c#

public static List<DateTime> GetWeekdayInRange(this DateTime from, DateTime to, DayOfWeek day)
    {
        const int daysInWeek = 7;
        var result = new List<DateTime>();
        var daysToAdd = ((int)day - (int)from.DayOfWeek + daysInWeek) % daysInWeek;

        do
        {
            from = from.AddDays(daysToAdd);
            result.Add(from);
            daysToAdd = daysInWeek;
        } while (from < to);

        return result;
    }
Posted by: Guest on July-22-2020

Code answers related to "Get all dates of every monday between two dates in c#"

C# Answers by Framework

Browse Popular Code Answers by Language