Pages

Thursday, April 3, 2014

Powerbuilder Function to Get Last Date in Month

This function is to get last date in particular month

Create a function named f_lastdate

Specify a date type as return value
Specify a date type parameter name dTgl, then type this script below

1:  integer iMonth, iDate  
2:  iMonth = Month(dTgl)  
3:  CHOOSE CASE iMonth  
4:       CASE 1, 3, 5, 7, 8, 10, 12  
5:            iDate = 31  
6:       CASE 4, 6, 9, 11  
7:            iDate = 30       
8:       CASE 2  
9:            IF isDate( '29/' + String(iMonth) + '/' + String(Year(dTgl))) THEN  
10:                 iDate = 29  
11:            ELSE  
12:                 iDate = 28  
13:            END IF  
14:  END CHOOSE       
15:  dTgl = Date( String(iDate) + '/' + String(iMonth) + '/' + String(Year(dTgl)))  
16:  RETURN dTgl  

To use the function, use this script

1:  Date dLastDate  
2:  dLastDate = f_lastdate(today())  

dLastDate value should be: 30 April 2014, if assume today is 3rd April 2014.