?
Solved

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

Posted on 2011-02-12
1
Medium Priority
?
1,242 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 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Working from home is a dream for many people who aren’t happy about getting up early, going to the office, and spending long hours at work. There are lots of benefits of remote work for employees.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

650 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