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;
    }

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
how to get two days before date in c# c# count weeks between two dates display all datetime values between two dates c# get all dates between two dates c# c# check two dates if date by one day c# calculate date difference in weeks c# datetime calculate how many days before monday how to get years between two dates in c# get day between two dates C# get the date between two dates c# get number of days between two dates in c# c# find days between to dates calculate the days in between two dates in c# get number of days between two dates excluding weekend in c# check current date between three date c# number of weeks between two dates c# c# datetime number of days between two dates c# get data between two dates time c# calculate number of working days between two dates get no of days between two dates c# get number of days between two dates c# c# exact number of days between dates c# get dates between two dates c# number of days between two dates find how many days between two dates inclusive C# c# get datetime -2 days find all weeknumbers between two dates c# how to get list of dates between two dates in c# check number of days between two dates c# how to get days number between 2 dates in c# c# datetime get days between two dates c# get all days between two dates how to get days between two dates in c# c# get the days between two dates c# get number of days between two dates c# get days between two dates get dates between two dates in c# search date frol list of dates c# days span between two dates in c# in days how to display data between two dates in asp net c# number of nights between two dates c# c# get monday date between two dates Get all dates of every monday between two dates in c#
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source