c# - Get Dates based on Current Date and List of Week Days -
I have something weird. I have a list of current date and weekdays. And I want all possible dates by the next date. Update: For example the link working - You can try this code, I have tested it and working properly You may need to increase this code so that it does not make any exception based on requirement. Update 2: You may have another way to accept weekdays in such a way that Therefore So you can pass any day of the week as much as you want. Hope this helps / div>
i.e. For today, its 22-04-2014 and Tuesday. The target date is 15-05-2014
I have 2 week days, Monday and Thursday. The code should be found near the weekday, which will be on Thursday. Therefore, it should return the date of Thursday, 24-04-2014 . Now, the next turn is from Monday which comes from the list. So now, it should be returned to Monday date which is 28-04-2014 .
It should be repeated until the target date.
So, the end result is
24-04-2014, 28-04-2014, 1-05-2014, 5-05-2014, 8-05-2014 Please, help me get this type of results here, Monday and Thursday are not fixed. It can happen any day and any day.
Private list & lt; DateTime & gt; Process Date (Date Time DTStartDate, DateTime Target) {DateTime DTLop = DTStartDate; // dtRequiredDates dates & dates to keep dates; DateTime & gt; DtRequiredDates = New List & lt; DateTime & gt; (); For (int i = dtStartDate.DayOfYear; i & lt; targetDate.DayOfYear; i ++) {if (dtLoop.DayOfWeek == DayOfWiki, Monday || dtLoop.DayOfWeek == DayOfWiki. Thursday) {dtRequiredDates.Add (dtLoop ); } DtLoop = dtLoop.AddDays (1); } Return dtRequiredDates; }
private list & lt; DateTime & gt; Process Date (Date Time DTStartDate, DateTime Date, List Lt; DayWeek & Day; DayOfWiki) {DateTime DTLop = DT StartDate; & Lt; Date Time & gt; DtRequiredDates = New List & lt; DateTime & gt; (); For (Int i = Ditistartdet. Dayof Waiyr; I & lt; targetDate.DayOfYear; i ++) {foreach (day Ofwaik days) {if (dtLoop.DayOfWeek == day) {dtRequiredDates.Add (dtLoop); }} DtLoop = dtLoop.AddDays (1); } Return dtRequiredDates;
Comments
Post a Comment