Thursday, August 19, 2010

Powerbuilder function to get business day

The function is to get total business days between 2 dates, it means we ignore the Saturday and Sunday.
The function need 2 parameters to pass with datetime type, called: adt_awal and adt_akhir, and will return Long type.

integer i, counter, li_daynumber, li_weeks, li_daysremained
long ll_daysafter

ll_daysafter = DaysAfter(date(adt_awal), date(adt_akhir))
li_weeks = ll_daysafter / 7
li_daysremained = mod(ll_daysafter,7)
counter = li_daysremained

FOR i = 1 TO counter
    li_daynumber = DayNumber(RelativeDate(date(adt_awal), i))
    IF li_daynumber = 1 OR li_daynumber = 7 THEN
       li_daysremained --
    END IF

RETURN (li_weeks * 5) + li_daysremained

To use this function, just type this script:

Long lBusinessDay
lBusinessDay = f_businessday(DateStart,DateEnd)

1 comment:

  1. Working perfectly. Thanks. You saved my day.