Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
AS/400 - Transfer not completing 11 278
debugger with zend php iseries 3 205
Read spool files from iseries in C# 4 209
iSeries PERL Scripts 7 132
In this article, I show you step by step with screenshots to assist you - HOW TO: Deploy and Install the VMware vCenter Server Appliance 6.5 (VCSA 6.5), with some helpful tips along the way.
A Short Story about the Best File Recovery Software – Acronis True Image 2017
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

747 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

13 Experts available now in Live!

Get 1:1 Help Now