Take a date and format to MDY in RPG IV

765 pts.
Tags:
AS/400 date format
AS400 RPGLE
RPG IV
I have a date coming in from a file (ADDate Zoned 8 0)

so it comes out 20090428

but I want to have it convert to 042809

how can I do that?

thanks

 

Answer Wiki

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

<pre>
h dftactgrp(*no) actgrp(*caller) option(*srcstmt:*nodebugio)

d dateISO s 8p 0 inz(20020125)
d dateMDY s 6p 0
d dateISOa s 8a inz(‘20020125′)
d dateMDYa s 6a
/free
dateMDYa = %char(%date(dateISOa:*iso0):*mdy0);
dateMDY = %dec(%date(dateISO:*iso):*mdy);
*inlr = *on;
dump(a);
/end-free

NAME ATTRIBUTES VALUE
DATEISOA CHAR(8) ‘20020125’ ‘F2F0F0F2F0F1F2F5’X
DATEMDYA CHAR(6) ‘012502’ ‘F0F1F2F5F0F2’X
DATEISO PACKED(8,0) 20020125. ‘020020125F’X
DATEMDY PACKED(6,0) 012502. ‘0012502F’X
* * * * * E N D O F R P G D U M P * * * * *
</pre>

Discuss This Question: 4  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.

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
  • TomLiotta
    Using what language? Also, is this an interactive program where a format conversion might run once every few minutes or a heavy batch process where you might do millions of conversions? Probably the most efficient in RPG would be to store the zoned value in a DS subfield. Redefine it with three character subfields for YY, MM and DD. Then either move those three into the desired order in a different DS so the DS can be referenced as a single value or EVAL the three into a 6-byte character variable. The same operations can be done in COBOL. If you want a more generic but less efficient process, you might use the CEE* date & time APIs in a service program the accepts an incoming value, e.g., '20090428', an incoming input format, e.g., 'YYYYMMDD', an incoming output format, e.g., 'MMDDYY, and have it return the converted value. The "picture string" feature of those APIs allows for some fancy flexibility. In CL, you might just use the CVTDAT command using FROMFMT*YYMMDD) TOFMT(*MDY) TOSEP(*NONE). You might even do this as a proc so you can call it from anywhere else. There are a number of alternatives from one end of the range to the other. Which is best for you might depend on language and application. Tom
    125,585 pointsBadges:
    report
  • Jaymz69
    RPG IV date comis in as 20020125 I want it to print out on the report 012502 just a small PRG for a report
    765 pointsBadges:
    report
  • CharlieBrowne
    Here is anotehr option DateOut = %subst(DateIn:5:4) + %Subst(DateIn:3:2)
    41,380 pointsBadges:
    report
  • TomLiotta
    just a small PRG for a report Suggestions from everyone else will work. The only thing to remember for each solution is that you need to convert your zoned-decimal numeric value to a character value before you can use %subst(). In BigKat's answer, the %date() function takes "an expression" as its first parameter, so it can work with packed or zoned input -- you should be good with the example. Also, your value is already in *ISO numeric format, so this should also work:
    dateMDY = %dec( %date( dateISO ) : *mdy );
    However, you're better off keeping the explicit specification. Tom
    125,585 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