[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details

How do I find a date within a range

Asked by tatton777 in Microsoft Visual C#.Net

I am having a difficult time writing some logic. I am creating a list of date ranges. For example...

October 1, 1999 12:00 am - October 6, 1999 11:59 pm
October 7, 1999 12:00 am - October 13, 1999 11:59 pm
October 14, 1999 12:00 am - October 19, 1999 11:59 pm
October 20, 1999 12:00 am - October 25, 1999 11:59 pm

This list is based on an employee history. The first week will have the first day the employee worked. The last week will contain the last day that the employee worked. I am having problems with the do while loop that stops the loop when the lastDayWorked is contained within the week range.

There is a bunch of code in between the DO and the WHILE but I am only concerned with the code in the parentheses of the WHILE statement. If you could help me through this brain cramp I would appreciate it.

Thanks
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
      do
      {
        firstDayOfWorkWeek = firstDayWorked;
        while (firstDayOfWorkWeek.DayOfWeek.ToString() != startDayOfWorkWeek)
        {
          firstDayOfWorkWeek = firstDayOfWorkWeek.AddDays(-1);
        }
 
        firstDayOfWorkWeek = new DateTime(firstDayOfWorkWeek.Year, firstDayOfWorkWeek.Month, firstDayOfWorkWeek.Day);
        lastDayOfWorkWeek = firstDayOfWorkWeek.AddDays(7);
        lastDayOfWorkWeek = lastDayOfWorkWeek.AddMilliseconds(-1);
 
        dtRow = dt.NewRow();
        dtRow["FIRSTDAY"] = firstDayOfWorkWeek;
        dtRow["LASTDAY"] = lastDayOfWorkWeek;
 
        lastDayWorkedIsAfterFirstDayInRange = lastDayWorked > firstDayOfWorkWeek;
        lastDayWorkedIsBeforeLastDayOfWorkWeek = lastDayWorked < lastDayOfWorkWeek;
        dt.Rows.Add(dtRow);
      }
      while (lastDayWorkedIsAfterFirstDayInRange IS SOME CONDITION&& lastDayWorkedIsBeforeLastDayOfWorkWeek IS SOME CONDITION);
[+][-]11/07/09 06:55 PM, ID: 25769240Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625