Return to the RPG Tips
Compute Number of days between two dates in RPG IV
To determine the number of days between two days in RPG, use our code, which shows two ways to calculate not only the number of days, but also the number of hours and minutes between two dates. D TmStmp1 S Z Inz( Z'2000-01-01-03.15.00.000000' ) D TmStmp2 S Z Inz( Z'1999-12-31-00.00.00.000000' ) D TmStmp3 S Z D Days S 11P 0 D Hours S 2P 0 D Minutes S 2P 0 D BigMinutes S 11P 0 * Technique 1 using successive SubDur operations C Eval TmStmp3 = TmStmp1 * Calculate Days C TmStmp3 SubDur TmStmp2 Days:*D C SubDur Days:*D TmStmp3 * Calculate Hours C TmStmp3 SubDur TmStmp2 Hours:*H C SubDur Hours:*H TmStmp3 * Calculate Minutes C TmStmp3 SubDur TmStmp2 Minutes:*MN C SubDur Hours:*MN TmStmp3 * Second technique is to calculate * minutes and then calculate the other values from there... C TmStmp1 SubDur TmStmp2 BigMinutes:*MN * Calculate days. C Eval Days = %Div( BigMinutes: 1440 ) C Eval BigMinutes = %Rem( BigMinutes: 1440 ) * Calculate Hours and minutes C Eval Hours = %Div( BigMinutes: 60 ) C Eval Minutes = %Rem( BigMinutes: 60 ) C Eval *INLR = *On By Mike Cravitz, NEWS/400 Technical Editor
[report a broken link by clicking here]