diff. between two date

35 pts.
Hello guys, I wanna do a one pgm which is find out date diff. between two date in rpg /400. Actually i did this in rpgiv...but now i want to do it in rpg/400. can somebody provide me a exact logic behind this.. Thanx in advance.....

Answer Wiki

Thanks. We'll let you know when a new response is added.

So in other words you don’t have the builtins for date calculations, right? I have an answer but it’s probably not the best. In the past you would call a CL and use the CVTDAT function in the CL to convert the dates to Julian, Do the arithmetic and use CVTDAT to convert the answer back to gregorian, or whatever format you’re looking for. Or, of course you could use QCMDEXC to call CVTDAT directly.

Discuss This Question: 5  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • Sloopy
    You could not use QCMDEXC to run CVTDAT, because CVTDAT returns values, and QCMDEXC cannot return those values to your program. Additionally, if the dates are in different years, straight arithmetic will not work with Julian dates - they are in YYDDD format, where DDD is the day number in the year. So, a straightforward subtraction will return an incorrect value if the dates are not in the same year. What you could do is either : a) Write a date arithmetic program in RPGIV and call it from your RPG/400 programs, or b) Write a date arithmetic program in RPG/400 and call it from your RPG400 programs. If you want option (b), then the trick is to reduce your incoming dates to single numbers. This is usually done using a base date - 01-Jan-1901 is popular. Then with both dates reduced to 'days since 1901-01-01', arithmetic is easy. If you write this as a utility program, make it perform more than one function. Use a parameter to tell the program what it should do - for example :
    *DIFF          - return the difference between two dates
    *ADDDUR        - return the date after adding days to date
    *SUBDUR        - return the date after subtracting days from date
    *CVTDAT        - Convert date from one format to another
    Your program should handle date formats as described in the manuals:
    *CYMD          - CYYMMDD (IBM format)
    *ISO           - CCYYMMDD
    *DMY           - DDMMYY
    ....and so on. Your parameter list may look like this:
    PARM           P1RTCD   7    Returns error code or blank
    PARM           P1OPTN   7    Option - see above
    PARM           P1DAYO   90   Returns number of days
    PARM           P1DATE   80   Returns converted date
    PARM           P1DAT1   80   First date in
    PARM           P1DTF1   5    First date format
    PARM           P1DAT2   80   Second date in
    PARM           P1DTF2   5    Second date format
    PARM           P1DAYI   90   Number of days in
    I would like to say that this sort of thing is fun to write. But if you don't happen to agree with that, I may have a routine in RPG/400 which will do what you want, on request. Regards, Sloopy
    2,195 pointsBadges:
  • Gilly400
    Hi, I used to have a CL program to do this sort of thing. It used a "zeller's congruence" routine that I lifted from somewhere. I'm not sure if I still have it, but I'll take a look. Regards, Martin Gilbert.
    23,730 pointsBadges:
  • astradyne
    Basically you need to convert the date into a number of days value and the simplest way of doing this is to first split the date out in to it's constituent parts of day, month and year. In your program have a 12 dimension array with the number of days passed per month - i.e. element 1 (January) would be zero, element 2 (February) would be 31, element 3 (March) 59, etc. Your basic date conversion formula would be:
         NoDays = ((year - 1) * 365.25) + Array(month) + days
    To take into account leap years, you would have two arrays - one for normal years and one for leap years. The leap year one would have 60 in element 3 and so on. Your program would then have to decide which array to use based on the year value (I'll use yyyy for the four digit year and yy for the two digit):
         if (yyyy / 400) = %int(yyyy / 400) or
            (yy / 4) = %int(yy / 4) and (yy<> 0)
              NoDays = ((year - 1) * 365.25) + Leap(month) + days
              NoDays = ((year - 1) * 365.25) + NonLeap(month) + days
    Not perfect, but should be good enough. Jonathan
    370 pointsBadges:
  • Alicsc
    Hi Martin/Sloopy, Pls post me the routines to calculate diff between dates in RPG/400. and post all such routines on dates. my email id is msali37@gmail.com
    370 pointsBadges:
  • Cwc
    Why bother using RPG III/400 coding methods? They're obsolete and not that marketable. And practically speaking, it takes longer to code such routines in RPG III than using the built in functionality of the modern version of the language. In 2008, it is past time to at least get with the 1990s. You can create an RPG IV program that can handle all the date maniupulation you'd need, which could be called from an RPG III program
    4,290 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: