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

Calculating 1st Business day of the Month

Status
Not open for further replies.

kskid

Technical User
Mar 21, 2003
1,767
US
CR 8.5 Developer
Oracle 8i using Oracle ODBC Connectivity

I know it's simple but it's a Friday and I think I lost it.


Using Ken Hamady's formula #17, I made some modifications to accommodate a holiday table, {calendar_exceptions}, to add 15 business days to a Send date

Code:
//Adding Business Days:
WhileReadingRecords;
DateVar Target := {@SendDate}; // Put your field name in here
NumberVar Add:= 15; // put the number of days here to add (a positive number)
NumberVar Added := 0;

WHILE Added < Add 
Do (target := target +1;
    if dayofweek (target) in 2 to 6 and not (target = {CALENDAR_EXCEPTIONS.EXCEPTION_DATE}) 
        then Added:=Added+1
        else Added:=Added);
Target

Currently {@SendDate} is first day of the month. I have been able to adjust the date to the 1st business day of the month if it falls on a weekend or holiday as follows.
Code:
WhileReadingRecords;
datevar target := dateserial(year(currentdate),month(currentdate)+1,1);
if dayofweek(target) in [2 to 6] and not(target = {CALENDAR_EXCEPTIONS.EXCEPTION_DATE} then
 Target
else if dayofweek(target) = 7 then
 target + 2
else
 target + 1

The problem with this formula is that target + 1, target + 2, dayofweek(target) may fall on a holiday.

How do I make the proper adjustments to come up with the first business day of the month.

Thanks,
-LW





 
I think I solved it but I'll let the guru's evaluate it.

Code:
WhileReadingRecords;
datevar target := dateserial(year(currentdate),month(currentdate)+1,1);

while dayofweek(target) in [1,7] or target = {CALENDAR_EXCEPTIONS.EXCEPTION_DATE}
do target = target + 1;

target

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top