[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Convert 6 digit dec date field to char MM/DD/YYY

Posted on 2011-02-12
1
Medium Priority
?
1,246 Views
Last Modified: 2012-08-13

What is the easiest way to convert a 6 digit dec date field to char MM/DD/YYY?  There needs to be a leading zero on the month.

021511 becomes "02/15/2011"
0
Comment
Question by:roosterup
1 Comment
 
LVL 36

Accepted Solution

by:
Gary Patterson earned 200 total points
ID: 34882933
For print or display, "D" fields formatted with the DATFMT(*USA) keyword work nicely. Use the %DATE BIF to get from numeric to date format.  It is just one easy extra step to convert from date to character if you need to end up there.

D yymmdd   s     6p 0     inz('021511')
D usaDate   s     d         datefmt(*usa)
D usaChar   s  10a        

/free

    // Verify numeric filed holds a valid date
    test(de) *YMD yymmdd ;

    if %error();
        // Bad date, for example "000000".  Handle error.
        dsply 'Bad date' ;

    else ;
         // Convert from numeric MDY to date
         usaDate = %date(mmddyy : *MDY) ;
         dsply usaDate ;

         // Convert from date to character, specify to convert to USA format
         usaChar = %char(usaDate : *USA) ;
         dsply usaChar ;

    endif ;
    *inlr = *on ;
 /end-free

Here's a nice article on date handling in RPG:  http://www.itjungle.com/fhg/fhg051904-story01.html
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Strategic internal linking is often considered an SEO power technique, especially for content marketing. Do you need to hire an SEO agency to optimize you internal linking? No, this article will help you understand the basics of internal linking and…
Exchange administrators are always vigilant about Exchange crashes and disasters that are possible any time. It is quite essential to identify the symptoms of a possible Exchange issue and be prepared with a proper recovery plan. There are multiple…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question