Solved

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

Posted on 2011-02-12
1
1,226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 35

Accepted Solution

by:
Gary Patterson earned 50 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
iSeries - Add Users to a Group 1 239
Issue Copying Tables/Files from one iSeries to Another 19 112
AS400 Logging Print device 2 89
iSeries DB2 query across local and remote site 4 102
A lot of things can happen during a presentation, worst of which is “death by PowerPoint.” Here are a few mistakes to avoid to make your slides clean.
Digital services have impacted the providers of three major areas: revenue generation, enhanced customer experience, and cost optimization. An increase in revenue generation through the use of modern upsells whilst giving digital services to the cus…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

731 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