Kwasi Denkyira

Kwasi Denkyira

  • 1.5k
  • 197
  • 14.8k

How to get the First, second and third Monday of the month b

Apr 10 2019 11:55 AM
I want to get the first, second and third Monday of the Month between two dates. I can get the first Monday of the month but not between two day. Below is my code. Any help will be appreciated.
  1. class Program  
  2.    {  
  3.        public class BusinessWeekDays  
  4.        {  
  5.            public DateTime Tuesday;  
  6.            public DateTime Monday;  
  7.        }  
  8.         
  9.   
  10.        static void Main(string[] args)  
  11.        {  
  12.            var StartDate = DateTime.Parse("04/25/2019");  
  13.            var SeriesEndDate = DateTime.Parse("09/30/2019");  
  14.   
  15.            for (int mth = 1; mth <= 12; mth++)  
  16.            {  
  17.                DateTime dt = new DateTime(2010, mth, 1);  
  18.                while (dt.DayOfWeek != DayOfWeek.Monday)  
  19.                {  
  20.                    dt = dt.AddDays(1);  
  21.                }  
  22.                Console.WriteLine(dt.ToLongDateString());  
  23.            }  
  24.            Console.ReadLine();  
  25.            //for (var i = StartDate; i < SeriesEndDate; i = i.AddMonths(Monthly))  
  26.            //{  
  27.   
  28.            //    months.Add(new BusinessWeekDays { Tuesday = dt, Monday = dt.AddDays(7) });  
  29.   
  30.            //    Console.WriteLine(months);  
  31.            //}  
  32.        }  
 

Answers (1)