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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

30 Business days from Current Date. 1

Status
Not open for further replies.

vbtech

Technical User
Jan 2, 2002
2
US
I apologize if this has already been answered, but I didn't find the thread. I'm looking for a way to find the business day 30 days from a start date. In my example I'm using the current date. The formula just counts 30 days and ignores the If/then conditions. Any help would be greatly appreciated.
-------------------------------
beforereadingrecords;

local numbervar counter := 0; //counter for the loop in the formula

datevar BusinessDate := CURRENTDATE; //Initialize display date to current date

datevar startdate := CURRENTDATE; //Initialize start/loop date to current date

//Initialize holiday array
datevar array holidays := [Date(2004,01,01), Date(2004,01,19), Date(2004,02,16), Date(2004,05,31), Date(2004,07,05), Date(2004,09,06), Date(2004,10,11), Date(2004,11,11), Date(2004,11,24), Date(2004,12,25)];


while counter < 30 do // Count 30 days
(
if dayofweek(startdate + counter) in [7, 1] // weekends
or startdate + counter in holidays
then
BusinessDate := startdate // Basically, do nothing
else
BusinessDate := startdate + counter; //Assign the current value of the start date to the business date
counter := counter + 1; // increment counter
);
BusinessDate // return business date
 
Try:

datevar TheDate := CURRENTDATE;
datevar Thirtydate;
numbervar x;
numbervar y;
datevar array holidays := [Date(2004,01,01), Date(2004,01,19), Date(2004,02,16), Date(2004,05,31), Date(2004,07,05), Date(2004,09,06), Date(2004,10,11), Date(2004,11,11), Date(2004,11,24), Date(2004,12,25)];
for x := 1 to 30 do(
for y := 1 to 7 do(
if dayofweek(TheDate+1) in [2 to 6]
and
not(TheDate+1 in holidays )
then
(
y := 8;
TheDate := TheDate+1;
)
else
(
TheDate:=TheDate+1;
)
);
);
TheDate

-k
 
vbTech,
You seem to be incrementing counter for every pass. You only want to increment counter if startdate + counter is not a weekend or holiday. You will need a second counter to advance the date.

beforereadingrecords;

local numbervar counter1 := 0; // increment business days
local numbervar counter2 := 0; // increment date

datevar BusinessDate := CURRENTDATE;
datevar startdate := CURRENTDATE; //Initialize start/loop date to current date

//Initialize holiday array
datevar array holidays := [Date(2004,01,01), Date(2004,01,19), Date(2004,02,16), Date(2004,05,31), Date(2004,07,05), Date(2004,09,06), Date(2004,10,11), Date(2004,11,11), Date(2004,11,24), Date(2004,12,25)];


while counter1 < 30 do // Count 30 business days
(
if dayofweek(startdate + counter2) in [7, 1] // weekends
or startdate + counter2 in holidays
then
counter1 := counter1 + 1; // increment business days counter
else
counter1 := counter1
counter2:= counter2 + 1 // increment date counter
BusinessDate := startdate + counter2; //Assign the current value of the start date to the business date

);
BusinessDate // return business date
 
Oops,
I incremented counter for holiday and weekends in previous post.

Should be:

while counter1 < 30 do // Count 30 business days
(
if dayofweek(startdate + counter2) in [7, 1] // weekends
or startdate + counter2 in holidays
then
counter1 := counter1

else
counter1 := counter1 + 1; // increment business days counter
counter2:= counter2 + 1 // increment date counter
BusinessDate := startdate + counter2; //Assign the current value of the start date to the business date

);
BusinessDate // return business date
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top