Date Formatting

100 pts.
Tags:
AS/400
IBM iSeries
RPG Date Formatting
 

I have a date field in a file (2010-04-20)

What is the cleanest way to output this to a display file as 20/04/2001?  (in RPGIV - not Free-format)?

Thanks in advance

Martin

 



Software/Hardware used:
as400, iSeries

Answer Wiki

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

If the field in the file is definded as a date data type, you can do the following:

<pre>
D DMYDATE S D DATFMT(*DMY)
D DATEFLDYMD S D INZ(D’2010-04-20′)

C EVAL DMYDATE = DATEFLDYMD

</pre>

DMYDATE now has a value of 20/04/10. If you want to keep the four digit year, then the only thing I can think of would be to set up a data structure to strip out the month, day and year then rearrange them in the order you want.

Discuss This Question: 10  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
    A very cursory glance didn't uncover a combination date format and separator that is best. I won't be surprised if one exists and someone supplies it though. If no clear examples show up, I'd probably just go with the various CEE* APIs. My output date string would come from CEEDATE with a picture string like 'DD/MM/YYYY' or 'ZD/MM/YYYY' maybe. Tom
    125,585 pointsBadges:
    report
  • DanTheDane
    Your challenge hit me.. could it be done ? - Well here is a solution to discuss/improve in pure RPG: To output you need the edited date in a char-field; - a fairly straight forward task if it shall not be in the dd/mm/yyyy format. Alas one can only get a ddmmyy 6-digit fomat, which may be edited in an editword BUT, creating an editword with inserted constant '20' leave us with a zero in the editword, whisch has a special meaning. Hmmm. The following executable estpgm includes m solution:
    d dato            s               d   inz(D'2010-04-20')             
    d chardate        s              8                                   
    d numdate         s              6  0                                
    d dspdate         s             10                                   
    c                                                                    
    c                   eval      chardate = %char(dato:*dmy0)           
    c                   eval      numdate  = %dec(chardate:6:0)          
    c                   eval      dspdate  = %editw(numdate:'  /  /2x  ')
    c     'x':'0'       xlate     dspdate       dspdate                  
    c                                                                    
    c                   eval      *inLR = *on                      
    
    Debugging the progam shows this content o fields: CHARDATE = '200410 ' NUMDATE = 200410. DSPDATE = '20/04/2x10' DSPDATE = '20/04/2010' <--- Voila It could be done... DanF
    2,555 pointsBadges:
    report
  • TomLiotta
    Yeah, there are certainly ways to get it done. If the RPG is current, perhaps a simple EVAL-CORR would be "cleanest". I use the CEE* APIs a lot because they are so flexible. You can invent date formats on-the-fly if necessary and basic procedures over them are nicely usable by any other language. But I was surprised not to find a DD/MM/YYYY format. After Y2K, that need should be a no-brainer. Tom
    125,585 pointsBadges:
    report
  • ten2008
    Hi Dan, what you have shown in the code is not working. I have tried the same code on the system. ANd it is giving the following eror. A character representation of a numeric value is in error (C G D F). This is happening at your 2nd C spec i.e: eval numdat=%dec(chardat:6:0). plz give the right code. thanks Ram
    1,150 pointsBadges:
    report
  • DanTheDane
    hi Ram, I re-tested my solution by copying the advised code to another machine running with V5R4 (My prod hw is on V6R1 soon going to V7R1 -I just recieved th CDs today :-). The program worked just fine. To help you through (..I wonder if Ricca has tested the solution?), you may 1. re-validate the code 2. cut/paste your version of my pgm, put it in an email and send it to my, and I'll report back. DanF dan@adfo.dk
    2,555 pointsBadges:
    report
  • Canuhp
    Thank you so much!!! I have been banging my head on the wall about this for a week!!
    235 pointsBadges:
    report
  • Canuhp
    LOL!! Posted the above comment to the wrong discussion. See the head banging is causing brain damage....
    235 pointsBadges:
    report
  • BigKat
    Try this
    c                   eval      output = %xlate('.':'/':%char(%date():*eur))
    8,200 pointsBadges:
    report
  • BigKat
    if it is defined as date, replace the %date() with your date field if it is defined as character, replace %date() with %date(fld:*iso) note *iso is not required, but I like to include it
    8,200 pointsBadges:
    report
  • BigKat
    also, it looks like something is going funny with the quotes I pasted in. they should be just simple single quotes.
    8,200 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