Calculating Business Days Between Two Dates

Check := @If(Startdate = ""; 1; EndDate = ""; 1; 0);
@If(Check; @Do(@Prompt([OK]; "No Values"; "You must enter starting and ending
dates."); @Return("")); "");
HolidayList := @DbColumn(""; ""; "($Holidays)"; 2);
@SetField("Holidays"; HolidayList);
@Environment("HolidayList"; @Implode(HolidayList; ";"));
@Environment("Iterations"; @Text(((EndDate - StartDate) / (24 * 60 * 60)) + 1));
@Environment("StartDate"; @Text(StartDate));
@Environment("SlidingDate"; @Text(StartDate));
@Environment("EndDate"; @Text(EndDate));
@Environment("WorkDays"; "0");
@Command([ToolsRunMacro]; "($Add-A-Day)")
Execute-Once Macro "($Add-A-Day)":
REM "ADD-A-DAY Macro";
REM "Recursive macro to check if dates fall on weekends ";
REM "and holidays and increment a working day count.";
REM "Retrieve all the environment variable";
Iterations := @TextToNumber(@Environment("Iterations"));
Sdate := @TextToTime(@Environment("SlidingDate"));
EndDate := @TextToTime(@Environment("EndDate"));
WorkDays := @TextToNumber(@Environment("WorkDays"));
Holidays := @Explode(@Environment("HolidayList"); ";");
REM "Calculate Add a Day - will be zero or one";
AddDay := @If(@Weekday(Sdate) = 1; 0; @Weekday(Sdate) = 7; 0; Sdate > EndDate;
0; @Text(Sdate) = Holidays; 0; 1);
REM "Check if there are any more iterations to do";
REM "If not, call a macro to update the fields";
REM "If yes, then save the new values and call the recursion routine";
@If(Iterations = 0; @Do(@Command([ToolsRunMacro]; "($SetNumDaysField)");
@Command([EditDocument]; "1")); @Do(@Environment("Iterations"; @Text(Iterations
- 1)); @Environment("SlidingDate"; @Text(@Adjust(Sdate; 0; 0; 1; 0; 0; 0)));
@Environment("WorkDays"; @Text(WorkDays + AddDay)); @Command([ToolsRunMacro];
Execute-Once Macro "($Recurs-Add)":
@Command([ToolsRunMacro]; "($Add-A-Day)");
Filter Macro "($Recurs-Add)":
FIELD NumDays := @Environment("WorkDays");

This was first published in November 2000

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.