150 pts.
 Time Elapsed
I am getting the wrong result in the %DIFF function. See following code:

D total_hours s 9 2 inz(0)

D time1 S t inz(T'12.00.00')

D time2 S t inz(T'13.38.00')

 /Free total_hours = %diff(time2 : time1 : *h);

 *inLR = *on;

 /End-Free

C RETURN

I was expecting 1.38. and I am getting 1.00.

Any suggestions?

 



Software/Hardware used:
RPGLE AS/400
ASKED: January 12, 2012  6:57 PM
UPDATED: March 17, 2012  5:39 AM

Answer Wiki:
Total hours is defined as numeric and should be defined as a time field like your ither fields.
Last Wiki Answer Submitted:  January 12, 2012  7:12 pm  by  CharlieBrowne   32,785 pts.
All Answer Wiki Contributors:  CharlieBrowne   32,785 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

%diff(time2 : time1 : *h); *h — number of hours — 1 hour

%diff(time2 : time1 : *minutes); number of minutes
returns not 1.38 but 60 + 38 = 98

Hope this helps
Phil

 44,070 pts.

 

Actually, %DIFF returns an integer of the number of FULL units between the 2 values

so you will only see 1.00 in your total hour field what you want is to retrieve the minutes divided by 60;

d total_hours     s              9p 2                 
d time1           s               t   inz(T'12.00.00')
d time2           s               t   inz(T'13.38.00')
                                                      
 /free                                                
     total_hours = %diff(time2 : time1 : *mn)/60;     
     dump(a);                                         
     *inlr = *on;                                     
 /end-free                                            
 7,175 pts.

 

Thanks for your help.

 150 pts.