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

]]>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

]]>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 else NoDays = ((year - 1) * 365.25) + NonLeap(month) + days endif

Not perfect, but should be good enough.

Jonathan

]]>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.

]]>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:

CALL 'DATCONV' 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

]]>