%DIFF Built-In Functions in rpgle

%DIFF function is used to find difference between Two Date, Time, or Timestamp Values.

The structure of %DIFF() function is as given below:

%DIFF(op1:op2:*MSECONDS|*SECONDS|*MINUTES|*HOURS|*DAYS|*MONTHS|*YEARS)
%DIFF(op1:op2:*MS|*S|*MN|*H|*D|*M|*Y)

%DIFF produces the difference (duration) between two date or time values. The first and second parameters must have the same or compatible types.

The following combinations are valid for getting the difference:

  •      Difference b/w two Dates
  •      Difference b/w two Times
  •      Difference b/w two Timestamps
  •      Difference b/w Date and timestamp (only the date portion of the timestamp is taken to have the difference)
  •      Difference b/w Time and timestamp (only the time portion of the timestamp is taken to have the difference)

The third parameter specifies the unit in which the difference will be. The following units are valid:

§  Difference b/w two dates or Difference b/w a date and a timestamp: *DAYS, *MONTHS, *YEARS

§  For two times or a time and a timestamp: *SECONDS, *MINUTES, *HOURS

§  Difference b/w two timestamps: *MSECONDS, *SECONDS, *MINUTES, *HOURS, *DAYS, *MONTHS, *YEARS

Example –%diff built-in function in rpgle




 Columns . . . :    6  80                                              AMIT/QRPGSRC
 SEU==>                                                                     TESTRPG
 FMT *   *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8
        *************** Beginning of data *****************************************
0001.00 D time1           s               T   INZ(T'12.51.57')                     
0002.00 D time2           s               T   INZ(T'11.50.57')                     
0003.00                                                                            
0004.00 D date1           s               D   INZ(D'2017-12-28')                   
0005.00 D date2           s               D   INZ(D'2017-11-08')                   
0006.00                                                                            
0007.00 Ddays_diff        S              2P 0                                      
0008.00 Dtime_diff        S              2P 0                                      
0009.00                                                                            
0010.00  /FREE                                                                     
0011.00     days_diff = %DIFF (date1: date2: *DAYS);                               
0012.00           // It gives the difference of dates in Days                      
0013.00                                                                            
0014.00     time_diff = %DIFF (time1: time2: *minutes);                            
0015.00           // It gives the difference of times in *minutes                  
0016.00   /END-FREE                                                                
0017.00                                                                            
0018.00 C     days_diff     dsply                                                  
0019.00 C     time_diff     dsply                                                  
0020.00 C                   SETON                                        LR        
        ****************** End of data ********************************************     


Output

DSPLY  50    
DSPLY  61   

 










User Comments:



Subscribe

  Email:



Copyright © www.go4as400.com, 2013-2017. Copyright notice