Get last/next week Wednesday date in C#
c#
Solution
To find the next Wednesday just keep adding days until you find one. To find the previous Wednesday just keep subtracting days until you get to one.
DateTime nextWednesday = DateTime.Now.AddDays(1);
while (nextWednesday.DayOfWeek != DayOfWeek.Wednesday)
nextWednesday = nextWednesday.AddDays(1);
DateTime lastWednesday = DateTime.Now.AddDays(-1);
while (lastWednesday.DayOfWeek != DayOfWeek.Wednesday)
lastWednesday = lastWednesday.AddDays(-1);
Problem
How would I get last week Wednesday and next week Wednesday's date in C#: ``` public Form1() { InitializeComponent(); CurrentDate.Text = "Today's Date: " + DateTime.Now.ToString("dd/MM/yyyy"); CurrentRent.Text = "Current Rent Date: "; // last wednesday NextRent.Text = "Next Rent Date: "; // next wednesday } ```