On Sep 26, 9:32*am, "Mike" <whyyoulookinga...@gmail.comwrote:
I'm trying this which I found online some time back:
public void AddWeekdays(DateTime start, int days)
* * {
* * * * try
* * * * {
* * * * * * if (start.DayOfWeek == DayOfWeek.Saturday || start.DayOfWeek ==
DayOfWeek.Sunday)
* * * * * * {
* * * * * *}
* * * * * *else
* * * * * * {
* * * * * * * * int remainder = days % 5;
* * * * * * * * int weekend = (5 / days) *2;
* * * * * * * * DateTime end = start.AddDays(remainder);
* * * * * * * * if (end.DayOfWeek == DayOfWeek.Saturday)
* * * * * * * * {
* * * * * * * * * * end = end.AddDays(2);
* * * * * * * * }
* * * * * * * * else if (end.DayOfWeek < start.DayOfWeek)
* * * * * * * * {
* * * * * * * * * * end = end.AddDays(2);
* * * * * * * * }
* * * * * * * * txtWDays.Value = weekend.ToString();
* * * * * * * * txtCDates.Text = end.AddDays(days + weekend -
remainder).ToShortDateString();
* * * * * * }
* * * * }
* * * * catch (Exception ex)
* * * * {
* * * * }
* * }
"Family Tree Mike" <FamilyTreeM...@discussions.microsoft.comwrote in
messagenews:43**********************************@m icrosoft.com...
Can you post your code?
"Mike" wrote:
I have a routine that's calculating business days but its not counting
the
weekend days that are between the start date and end date. If my start
date
is 9/26/08 and my end date is 10/01/08, I should see 4 business days and
2
weekend days.
How can I get that result? I'm getting 4 business days but its not
counting
the weekend days?
If you still want to use your code logic, you need change the code
like the following
public void AddWeekdays(DateTime start, int days)
{
try
{
if (start.DayOfWeek == DayOfWeek.Saturday ||
start.DayOfWeek ==
DayOfWeek.Sunday)
{
}
else
{
int remainder = days % 5;
int weekend = ( days / 5) *2; // change here
DateTime end = start.AddDays(remainder);
if (end.DayOfWeek == DayOfWeek.Saturday)
{
end = end.AddDays(2);
}
else if (end.DayOfWeek < start.DayOfWeek)
{
end = end.AddDays(2);
}
txtWDays.Value = weekend.ToString();
txtCDates.Text = end.AddDays(days - weekend -
remainder).ToShortDateString(); //change here
}
}
catch (Exception ex)
{
}
}
Try this code and let me know if it works.