Solved

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

Posted on 2011-02-12
1
1,220 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 34

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now