## ISO date Formats and Move

pts.
Tags:
RPG
RPGLE
I need to do 2 things . Perform day additions and deductions on a date format yyyymmdd. Am I correct in thinking this is *ISO format? And is there any example code of arithmetic? 2. Also I have been advised on RPG4 not to use MOVE to change char to dec. Is this correct, and what alternatives are suggested? Sorry this is basic stuff but I am on a very steep learning curve to RPG4 after 5 years out Thanks

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

Hi

No it’s not ISO. ISO is “YYYY-MM-DD” with the separators specified. Having said that it’s as ISO as you would get in a numeric field.

The easiest way to do arithmetic is using date type fields and then using the %Days, %Months and %Years built in functions. The following RPG IV program demonstrates the use of date fields and arithmetic:

D MyDecDate s 8s 0 Inz(20061231)

D MyDateISO s d DatFmt(*ISO)
D MyDateEUR s d DatFmt(*EUR)
D MyDateUSA s d DatFmt(*USA)

C* Convert the decimal date to ISO format…
C Eval MyDateISO = %Date(MyDecDate : *ISO)
C MyDateISO Dsply

C* Moving between date type fields automatically changes the format…
C Eval MyDateEUR = MyDateISO
C MyDateEUR Dsply

C Eval MyDateUSA = MyDateEUR
C MyDateUSA Dsply

C* Date calculations can be done using Eval and %Days, %Months and %Years functions…
C Eval myDateISO = myDateISO + %Years(1) +
C %Months(6) + %Days(14)
C MyDateISO Dsply

C Eval *InLR = *On
C Return

A lot of the experts say to use free format RPG, which doesn’t allow MOVE. If, like me, you still use the extended fixed format layout then I would say to use Eval as it allows you to do more than a simple MOVE.

Unfortunately you can’t use “Eval Char=Numeric”, instead the accepted technique is to use edit codes to convert it:

Eval Char = %EditC(Numeric : ‘X’)

Edit code “X” does a straight conversion. To convert from numeric to character, use:

Eval Char = %Char(Numeric)

Hope it helps, any more questions please shout.

All the best

Jonathan