How would I get last week Wednesday and next week Wednesday\'s date in C#:
public Form1()
{
InitializeComponent();
CurrentDate.Text = \"Today\'s Date: \" +
Use the AddDays routine:
// increment by the number of offset days to get the correct date
DayOfWeek desiredDay = DayOfWeek.Wednesday;
int offsetAmount = (int) desiredDay - (int) DateTime.Now.DayOfWeek;
DateTime lastWeekWednesday = DateTime.Now.AddDays(-7 + offsetAmount);
DateTime nextWeekWednesday = DateTime.Now.AddDays(7 + offsetAmount);
That should do it!
NOTE: If it is a Monday, "Last Wednesday" is going to give you the very last Wednesday that occurred, but "Next Wednesday" is going to give you the Wednesday 9 days from now! If you wanted to get the Wednesday in two days instead you would need to use the "%" operator. That means the second "nextweek" statement would read "(7 + offsetAmount) % 7".