Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculating the number of Business Days between two dates

Formula Help

Calculating the number of Business Days between two dates

by  Reebo99  Posted    (Edited  )
Use the following formula, replacing the items in Bold with your start/end date and the items in Italics with your holidays........

WhilePrintingRecords;
[color green]//Set the values of Start Date and End Date[/green]
DateVar StartDate := Date(2003,01,01);
DateVar EndDate := Date(2003,12,31);

[color green]//Find out the difference in days and subtract the weekends[/green]
NumberVar DaysDiff := DateDiff("d",StartDate,EndDate) -
DateDiff("ww",StartDate,EndDate,crsaturday) -
DateDiff("ww",StartDate,EndDate,crsunday);

[color green]//Create an array of Holiday dates[/green]
Local DateVar Array Holidays := MakeArray(
Date(2003,01,01),
Date(2003,01,02),
Date(2003,12,25),
Date(2003,12,26),
Date(2003,07,07)
);

[color green]//Loop through the array checking if each holiday is within the dates[/green]
Numbervar Counter := 0;
While UBound(Holidays) <> Counter do
(Counter := Counter + 1;
if Not(dayofweek(Holidays[Counter]) in [1,7]) and
Holidays[Counter] in StartDate to EndDate then DaysDiff := DaysDiff -1;);

[color green]//Display result to 0 decimal places and no thousand separator[/green]
totext(DaysDiff,0,"");
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top