RPG IV Date Formatting

100 pts.
Tags:
RPG
RPG Date Formatting
RPG IV
What is the best and cleanest way to convert a character date dd / mm / yy to *ISO format?

Answer Wiki

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

is this a numeric field or a character with/without the /’s?
*ISO format — in a date type field?
Phil

The date is an 8A field and therefore includes the ‘/’ . Therefore, the field contains dd/mm/yy. I need to convert this to ccyy-mm-dd

Martin

So your output is 10a?

————–

First and foremost, this should be a column defined as a DATE data type. Then virtually ANY SQL engine can manipulate it.

However, since you have an 8 byte CHAR filed that [hopefully] contains MM/DD/YY and you want YYYY-MM-DD.
> first you better edit the data
> a series of MOVE statements will accomplish the reformatting with an IF for the century
e.g. move ‘old mm’ to ‘new mm’
move ‘old dd ‘ to ‘new dd’
move ‘old yy’ to new yy’
and you will need a “pivot year” to determine which century to use.
e.g. If ‘old yy’ than 12 then move 20 to ‘new cc’
else move 19 to ‘new cc’

this is best done with a called module (sub routine) so EVERYONE in your company is using the same pivot year and for future maintenance.

By the way – every here of Y2K? Data like yours, and code like I suggest, is what got is in that mess. But, of course, back in the 70s and 80s when most of that old code was written storage was just too expensive to justify storing the century. I even recall the first system I worked that was written in 69 and it only used a ONE DIGIT year. So I had some experience with adjusting dates long before everyone else got scared of the year 2000.

————————————————————
All that Ricca said was true – and yes this would make an excellent procedure

D DATEIN S 8 INZ(’08/05/09′)
D DATETYPE S D
D DATEOUT S 10

C EVAL DATETYPE = %DATE(DATEIN : *MDY)
C EVAL DATEOUT = %CHAR(DATETYPE)

or as one step
C EVAL DATEOUT = %CHAR(%DATE(DATEIN : *MDY))

This will fail if DateIn is not a valid date which can be captured with a monitor black
C MONITOR
C EVAL DATEOUT = %CHAR(%DATE(DATEIN : *MDY))
C ON-ERROR
C …bad date
C ENDMON

——————

Discuss This Question: 1  Reply

 
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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Yorkshireman
    The RPG ILE manauals show lots of examples of date conversion. Which converts can be handled by opcodes and which cannot. the edited d/m/y field is common enough for the language to handle it. If needs be, construct a field analogous to *ISO, then revert to RPG to collect it and do whatever else you want to. You will want to ensure that all dates are valid. If this is 'old' data and alphameric, then its possible that type checking was not rigorous at the time it was created.
    5,580 pointsBadges:
    report

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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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

Following