## algorithm for this code

## algorithm for this code

(OP)

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.

## RE: algorithm for this code

16/9 result is 17/9

17/9 result is 18/9

...

20/9 result is 23/9

21/9 result is 23/9

22/9 result is 23/9

23/9 result is 24/9

Is this what you want or is it something completely different. Also, what is this lag you are talking about?

## RE: algorithm for this code

## CODE --> C#

## RE: algorithm for this code

Should be:

## CODE --> C#