Hello all,
I need help with a days between formula, the formula here is showing business days between 08/15/2003 and 08/22/2003 which should be 6 business days (SAT and SUN not included)
The formula is including the business days, can anyone see where the mistake is?
//CALCULATE THE NUMBER OF BUSINESS DAYS
//INCLUDING HOLIDAYS IN THE TOTAL
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//INPUT REQUIRED _ INPUT REQUIRED _ INPUT REQUIRED
//ENTER FIRST DATE
DateVar FirstDay:= Date(2003,08,15);
//ENTER END DATE
DateVar LastDay:= Date(2003,008,22);
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//END INPUT REQUIRED _ END INPUT REQUIRED _ END INPUT
//Other variables used in the formula
Numbervar Days;
Numbervar Weekends;
Numbervar Finaldays;
DateVar StartDate;
DateVar EndDate;
//BEGIN FORMULA:
//*********************************************************
//FINISH FORMULA IF FIRSTDAY OR LASTDAY IS NULL
//*********************************************************
IF FirstDay <=Date(0,0,0) or LastDay <=Date(0,0,0) then
Finaldays:= 0
//ELSE ASSIGN FINALDAYS
//*********************************************************
ELSE
(
//ASSIGN START DATE
//*********************************************************
//if the first day falls on a weekend, StartDate is equal
//the following Monday for calculation reasons
If DayOfWeek(FirstDay) = 7 Then
StartDate := FirstDay + 2
Else If DayOfWeek(FirstDay) = 1 Then
StartDate := FirstDay + 1
Else
StartDate:=FirstDay;
//ASSIGN END DATE
//*********************************************************
//if the last day falls on a weekend, EndDate is equal to
//the following Monday for calculation reasons
If DayOfWeek(LastDay) = 7 Then
EndDate := LastDay - 1
Else If DayOfWeek(LastDay) = 1 Then
EndDate := LastDay - 2
Else
EndDate := LastDay;
//CALCULATE DAYS (including today, First Day and Last Day)
//*********************************************************
Days:= (EndDate - StartDate) + 1;
//CALCULATE WEEKENDS
//*********************************************************
Weekends:= (EndDate - (dayofweek(EndDate)-1)) - (StartDate
+ (7-dayofweek(StartDate))) +1;
if Weekends = 2 then
Weekends:=Weekends
else if Weekends <=0 then
Weekends:=0
else
Weekends:= (((Weekends-2)/7)*2) + 2;
//CALCULATE FINAL DAYS (DAYS - WEEKENDS)
//*********************************************************
FinalDays:=Days-Weekends;
if FinalDays < 0 then
FinalDays:=0;
);
//DISPLAY NUMBER OF BUSINESS DAYS IN THE RANGE
//*********************************************************
FinalDays;days
I need help with a days between formula, the formula here is showing business days between 08/15/2003 and 08/22/2003 which should be 6 business days (SAT and SUN not included)
The formula is including the business days, can anyone see where the mistake is?
//CALCULATE THE NUMBER OF BUSINESS DAYS
//INCLUDING HOLIDAYS IN THE TOTAL
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//INPUT REQUIRED _ INPUT REQUIRED _ INPUT REQUIRED
//ENTER FIRST DATE
DateVar FirstDay:= Date(2003,08,15);
//ENTER END DATE
DateVar LastDay:= Date(2003,008,22);
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//END INPUT REQUIRED _ END INPUT REQUIRED _ END INPUT
//Other variables used in the formula
Numbervar Days;
Numbervar Weekends;
Numbervar Finaldays;
DateVar StartDate;
DateVar EndDate;
//BEGIN FORMULA:
//*********************************************************
//FINISH FORMULA IF FIRSTDAY OR LASTDAY IS NULL
//*********************************************************
IF FirstDay <=Date(0,0,0) or LastDay <=Date(0,0,0) then
Finaldays:= 0
//ELSE ASSIGN FINALDAYS
//*********************************************************
ELSE
(
//ASSIGN START DATE
//*********************************************************
//if the first day falls on a weekend, StartDate is equal
//the following Monday for calculation reasons
If DayOfWeek(FirstDay) = 7 Then
StartDate := FirstDay + 2
Else If DayOfWeek(FirstDay) = 1 Then
StartDate := FirstDay + 1
Else
StartDate:=FirstDay;
//ASSIGN END DATE
//*********************************************************
//if the last day falls on a weekend, EndDate is equal to
//the following Monday for calculation reasons
If DayOfWeek(LastDay) = 7 Then
EndDate := LastDay - 1
Else If DayOfWeek(LastDay) = 1 Then
EndDate := LastDay - 2
Else
EndDate := LastDay;
//CALCULATE DAYS (including today, First Day and Last Day)
//*********************************************************
Days:= (EndDate - StartDate) + 1;
//CALCULATE WEEKENDS
//*********************************************************
Weekends:= (EndDate - (dayofweek(EndDate)-1)) - (StartDate
+ (7-dayofweek(StartDate))) +1;
if Weekends = 2 then
Weekends:=Weekends
else if Weekends <=0 then
Weekends:=0
else
Weekends:= (((Weekends-2)/7)*2) + 2;
//CALCULATE FINAL DAYS (DAYS - WEEKENDS)
//*********************************************************
FinalDays:=Days-Weekends;
if FinalDays < 0 then
FinalDays:=0;
);
//DISPLAY NUMBER OF BUSINESS DAYS IN THE RANGE
//*********************************************************
FinalDays;days