simon taylor

simon taylor

  • NA
  • 38
  • 69.1k

Loop Assist

Jan 3 2011 11:59 AM

Hi guys, i was wondering if you could assist me with my query. I have created a 'Project Form' to allow the user to enter details for a new projct e.g name, start and end date of project ect.... What i am doing now is taking the start date and adding 7 days to it to set the end week for each week, then comparing it with the end date to see if it is earlier, the same or later. If it is ealier add this new the array list, else set this date as end date and add it to the array list. e.g If the start date was Monday 3rd Jan 2011, add 7 days = 10th Monday Jan 2010 (end week date) then check if it is ealier, the same or later than the end date. If it is earlier than add to array list and again +7 days again.
 
 
 
 

 
public void setWeeks()
{
stDate =
new DateTime();
enDate =
new DateTime();
DateTime[] dateArray = new DateTime[50];

endOfWeekDates =
new DateTime();
sevenDays =
new TimeSpan(7, 0, 0, 0); // represents 7 days
endWeeksList =
new ArrayList(1);

stDate = System.
DateTime.Parse(startDate); // convert string date to System.DateTime representation
enDate = System.
DateTime.Parse(endDate);


//endOfWeekDates = stDate.Add(sevenDays);

for (int i = 0; i < dateArray.Length; i++)
{
if (dateArray[i].Add(sevenDays) < enDate)
{
endWeeksList.Add(dateArray[i]);
}
else if (dateArray[i].Add(sevenDays) == enDate) // if same date add to list
{
endOfWeekDates = enDate;
endWeeksList.Add(dateArray[i]);
}
else if (dateArray[i].Add(sevenDays) > enDate) // if over the end date add to list
{
endOfWeekDates = enDate;
endWeeksList.Add(dateArray[i]);
}
MessageBox.Show("Dates are " + endWeeksList.ToString());

}
Here is my updated code above. Sorry for the sloppy presentation before, i did not realise my code did not look so great. 

Answers (13)