If I pass a date and the days that should be subtracted I need to find the next weekday. Here is what I have:
So Monday I've figured out it should be DayLag - 3. If I pass DayLag = 1 and BusDate is 9/23 then FileDate is 9/20. I can't figure out for the other days.
Please help.
Code:
static DateTime GetFileDate(DateTime BusDate, int DayLag)
{
DateTime FileDate;
FileDate = DateTime.Today;
switch (BusDate.DayOfWeek.ToString())
{
case "Monday":
FileDate = BusDate.AddDays(DayLag - 3);
break;
case "Tuesday":
if (DayLag == -3)
FileDate = BusDate.AddDays(-5);
else if (DayLag == -2)
FileDate = BusDate.AddDays(-4);
else if (DayLag == -1)
FileDate = BusDate.AddDays(-1);
break;
case "Wednesday":
if (DayLag == -3)
FileDate = BusDate.AddDays(-5);
if (DayLag == -2)
FileDate = BusDate.AddDays(-2);
if (DayLag == -1)
FileDate = BusDate.AddDays(-1);
break;
default:
FileDate = BusDate.AddDays(DayLag);
break;
}
return FileDate;
}
So Monday I've figured out it should be DayLag - 3. If I pass DayLag = 1 and BusDate is 9/23 then FileDate is 9/20. I can't figure out for the other days.
Please help.