Ü  %DIFF (Difference between Two Date, Time, or Timestamp Values)

The structure 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


/FREE
   num_days = %DIFF (date1: date2: *DAYS);    // It returns the no. of days b/w date1 & date2
   time = time + %DIFF (time1: time2: *minutes); // It returns the min. b/w time1 & time2
 /END-FREE

 





User Comments:





Copyright © Go4as400.com, 2013-2017. Copyright notice