Adding work days

freak

Member
Does anyone have a function made up that adds work days to a given date? For us, Saturday and Sunday are not work days. The starting date given may be a Saturday or Sunday. I am writing one but it's messy and I thought one of you genius coders may having something slick done already.
 
Here is what I came up with...

Code:
FUNCTION AddWorkDays RETURNS DATE (INPUT dt AS DATE, INPUT days AS INTEGER):
  DEF VAR i AS INTEGER INIT 1 NO-UNDO.
       DEF VAR returndate AS DATE NO-UNDO.

  returndate=dt.
  DO i=1 TO days:
    IF weekday(dt + i)=1 OR weekday(dt + i)=7 THEN
      days=days + 1.
        
    returndate=returndate + 1.
            
  END.
    
    RETURN returndate.

END FUNCTION.
 
Here in Canada, we have these things called "holidays" with funny names like "Christmas" and "Easter"; these make this sort of calculation much more complicated. Especially when different parts of the country (I'm talking to you, Quebec!) have different holidays from everyone else.
 
We have a table with holidays in it. I can incorporate that as well.
Code:
FUNCTION AddWorkDays RETURNS DATE (INPUT dt AS DATE, INPUT days AS INTEGER):
  DEF VAR i AS INTEGER INIT 1 NO-UNDO.
       DEF VAR returndate AS DATE NO-UNDO.

  returndate=dt.
  DO i=1 TO days:

    FIND FIRST holiday where holiday.holidaydate=dt + i no-lock no-error.

    IF weekday(dt + i)=1 OR weekday(dt + i)=7 or AVAILABLE(holiday) THEN
      days=days + 1.
        
    returndate=returndate + 1.
            
  END.
    
    RETURN returndate.


END FUNCTION.
 
BTW - When my friends from Europe take what we call vacation in the US, they say they are on holiday. Don't recall what they call a US holiday. I figured Canada followed Europe on that terminology but obviously not.
 
Back
Top