Snippets

SeanB Dataflex - Add business Days (Ignores holidays)

Created by SeanB last modified
Define DOW_Saturday for 7
Define DOW_Sunday for 1

Function AddBusinessDays Global DateTime dStartDate Integer iBusinessDays Returns DateTime
    Integer iDayOfWeek 
    Integer iAddDays 
    Integer iBaseWeek
    Integer iTotalDays 
    
    Move (DateGetDayOfWeek(dStartDate)) to iDayOfWeek 
    
    If ( iDayOfWeek = DOW_Saturday ) Move (DateAddDay(dStartDate,2)) to dStartDate
    Else If ( iDayOfWeek = DOW_Sunday ) Move (DateAddDay(dStartDate,1)) to dStartDate
    
    Move (iBusinessDays / 5) to iBaseWeek
    Move (mod(iBusinessDays,5)) to iAddDays
    Move (DateAddDay(dStartDate,(iBaseWeek*7))) to dStartDate

    Move (DateGetDayOfWeek(dStartDate)) to iDayOfWeek 
    If ((iDayOfWeek+iAddDays) > 7) Move (iAddDays+2) to iAddDays 
    Move (DateAddDay(dStartDate,iAddDays)) to dStartDate

    Move (DateGetDayOfWeek(dStartDate)) to iDayOfWeek 
    If ( iDayOfWeek = DOW_Saturday ) Move (DateAddDay(dStartDate,2)) to dStartDate
    Else If ( iDayOfWeek = DOW_Sunday ) Move (DateAddDay(dStartDate,1)) to dStartDate
    
    Function_Return dStartDate
End_Function 

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.