adding days to a date, bypass weekends

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I have a date in UK Format (dd/mm/yyyy). I want to get a series of days
after that date, but NOT Saturday or Sunday

For example, if the date is 13/12/2004 (next Monday) and I get the next 9
dates, I want to end up with a full list like.. 13, 14, 15, 16, 17, 20, 21,
22, 23, 24 (2wks, mon-fri).

How can I acheive this? (im using C#)

Cheers


Dan
 
Make a DateTime variable, increment it in a loop and check DayOfWeek
property.

Eliyahu
 
dhnriverside said:
Hi

I have a date in UK Format (dd/mm/yyyy). I want to get a series of days
after that date, but NOT Saturday or Sunday

For example, if the date is 13/12/2004 (next Monday) and I get the next 9
dates, I want to end up with a full list like.. 13, 14, 15, 16, 17, 20,
21,
22, 23, 24 (2wks, mon-fri).

How can I acheive this? (im using C#)

Did you look at the members of the DateTime structure?

John Saunders
 
Hi

Have checked out DateTime, and come up with the following code. It's
supposed to increment the dates by a week, and create a string of the dates...

DateTime dates;
dates = DateTime.Parse(txtSessionDate.Text); // txtSessionDate.Text =
15/12/2004
listOfDates = dates.ToShortDateString();
//weeks
for(x=0; x < Convert.ToInt32(txtRecurs.Text); x++)
{
xw = x * 7;
DateTime newdate;
newdate = dates;
newdate.AddDays(xw);
listOfDates += ", " + newdate.ToShortDateString();
}

It creates a string of dates, but the AddDays method doesn't seem to be
doing anything. It compiles, but all the dates in the string are the same?!

Cheers


Dan
 
dhnriverside said:
Hi

Have checked out DateTime, and come up with the following code. It's
supposed to increment the dates by a week, and create a string of the
dates...

DateTime dates;
dates = DateTime.Parse(txtSessionDate.Text); // txtSessionDate.Text =
15/12/2004
listOfDates = dates.ToShortDateString();
//weeks
for(x=0; x < Convert.ToInt32(txtRecurs.Text); x++)
{
xw = x * 7;
DateTime newdate;
newdate = dates;
newdate.AddDays(xw);
listOfDates += ", " + newdate.ToShortDateString();
}

It creates a string of dates, but the AddDays method doesn't seem to be
doing anything. It compiles, but all the dates in the string are the
same?!

AddDays is a function:

newdate = dates.AddDays(xw);

John Saunders
 
Back
Top