It is mostly maths, try this example to find the date for the Wednesday on 4th week of February 2016. Test it with other dates and parameter, say 5th week, it will cross over to March.
using System;
public class Program
{
public static void Main()
{
DateTime dt = new DateTime(2016, 2, 1);
DayOfWeek firstDayOfWeekofMonth = dt.DayOfWeek;
int myWeekNumInMonth = 4;
string myDayOfWeek = "Wednesday";
int myDayOfWeekInt = day2Int(myDayOfWeek);
int diff = myDayOfWeekInt - (int)firstDayOfWeekofMonth;
Console.WriteLine("The answer is {0:d}.", dt.AddDays(7 * (myWeekNumInMonth - 1) + diff));
}
public static int day2Int(string dayOfWeek)
{
switch (dayOfWeek)
{
case "Sunday":
return 0;
case "Monday":
return 1;
case "Tuesday":
return 2;
case "Wednesday":
return 3;
default:
return -1;
}
}
}
Find out more:
1.
DayOfWeek Enumeration[
^]
2.
DateTime.AddDays Method[
^]