public static DateTime GetDate(int year, EMonth month, EWeeksInMonth weekInMonth, EDaysOfWeekExt dayOfWeekExt) { int monthNumber = Month.GetMonthNumber(month); bool lookForward = true; DateTime date; switch (weekInMonth) { case EWeeksInMonth.First: date = new DateTime(year, monthNumber, 1); break; case EWeeksInMonth.Second: date = new DateTime(year, monthNumber, 8); break; case EWeeksInMonth.Third: date = new DateTime(year, monthNumber, 15); break; case EWeeksInMonth.Fourth: date = new DateTime(year, monthNumber, 22); break; case EWeeksInMonth.Last: date = new DateTime(year, monthNumber, DateTime.DaysInMonth(year, monthNumber)); lookForward = false; break; default: throw new ArgumentException($"Unrecognized Week in Month ({weekInMonth})!"); } if (lookForward) { while (!date.DateMatches(dayOfWeekExt)) { date = date.AddDays(1); } } else { while (!date.DateMatches(dayOfWeekExt)) { date = date.AddDays(-1); } } return(date); }