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.


1:  integer i, counter, li_daynumber, li_weeks, li_daysremained  
2:  long ll_daysafter  
3:    
4:  ll_daysafter = DaysAfter(date(adt_awal), date(adt_akhir))  
5:  li_weeks = ll_daysafter / 7  
6:  li_daysremained = mod(ll_daysafter,7)  
7:  counter = li_daysremained  
8:    
9:  FOR i = 1 TO counter  
10:       li_daynumber = DayNumber(RelativeDate(date(adt_awal), i))  
11:       IF li_daynumber = 1 OR li_daynumber = 7 THEN  
12:            li_daysremained --  
13:       END IF  
14:  NEXT  
15:    
16:  RETURN (li_weeks * 5) + li_daysremained  


To use this function, just type this script:

1:  Long lBusinessDay  
2:  lBusinessDay = f_businessday(DateStart,DateEnd)  

No comments:

Post a Comment