Unconfigured Ad Widget

Collapse

Announcement

Collapse
No announcement yet.

Convert Date

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Convert Date

    Can someone please give me example code in RPG IV how to do the simple task of converting a 8 digit numeric field in YYYMMDD format to a 6 digit field in MMDDYY format. My desired result is to display the date as MM/DD/YY. I am using the ISO format but am coming up with zeros in my result field. Please help.

  • #2
    Convert Date

    Assume "ccyymmdd" is your 8-digit date and "mmddyy" is your 6-digit date. Use the following code:
     d workdate S D C *ISO move ccyymmdd workdate C *MDY move workdate mmddyy 6 0 
    Joe

    Comment


    • #3
      Convert Date

      Joe, it still doesn't work. Something strange is going on here. Here is my code: FEDCMON IF E DISK * D workdate S D c read edcmon 10 c *ISO move eddate workdate c *MDY move workdate mmddyy 6 0 c z-add 1 x 1 0 c move *ON *INLR When I put it in step by step debug, Eddate (data base file) = 20000703. After the workdate line is executed. It's value is '001-01-01' When the mmddyy line is executed, it then steps to the *INLR line (skipping Z-add 1 to X). When I show variables at LR, it shows mmddyy = '000000' and X= 0. Any idea what is wrong? Thanks. Ron For some reason

      Comment


      • #4
        Convert Date

        Have you tried *ISO0 move eddate workdate (that's *ISOzero). *ISO format is yyyy-mm-dd and you have yyyymmdd.

        Comment


        • #5
          Convert Date

          A couple of questions. When you say that eddate = 20000703, is that as seen in debug, or what you know is on the file? What is the value of indicator 10 when after the read? From previous threads, for workdate to have the value you specify, it means that the value you are moving to it is not a valid date and is probably zero. That is why I suspect the value of eddate. Are you certain that eddate is 8/0? Russell

          Comment


          • #6
            Convert Date

            Yes may 8 numeric data field is 20000713. I tried changing *ISO to *ISO0 but got a compile error. 0072.00 c *ISO0 move eddate workdate The Date, Time, or Timestamp separator '0' is not allowed with numeric entry EDDATE. Indicator 10 is off so the file is being read and it is retrieving the correct numeric value in eddate 20000713. ron

            Comment


            • #7
              Convert Date

              Ron, What is your program definition of the field eddate? 8s0 or 8p0? Looks to me like it is 7s0 and that's the wrong length for an *iso numeric date and would explain why your *ISO native date field contains '000' instead of '2000' as the year. Is eddate really a *CYMD date? And, you would only need the zero in *iso0 if eddate is char 8a (a character field without without the '/' separators) instead of 8s0. Chris

              Comment


              • #8
                Convert Date

                Ron, whenever I've used a *SOURCE view and the debugger skips a line of code, it's always been caused by having changed the source but forgetting to recompile. That would probably explain the other oddities (your code looks correct to me).

                Comment


                • #9
                  Convert Date

                  You could define a date data type in your "D" specs - Let's call it MDYFIELD. The format would be *MDY. In your "C" specs, only one line is needed"
                  *ISO MOVE YYYYMMDD MDYFIELD
                  The slashes are already in MDYFIELD. Dave

                  Comment


                  • #10
                    Convert Date

                    Dave, I still can't get it to work using your or Joe's example. When I use your example, I get a value of 01/01/40 in workdate. When in debug, it skips the 'z-add 1 x' line and goes to LR. I am sure I have recompiled the source. My eddate field is not defined in the program, it is a database file that is Packed, length of 8, zero decimals. FEDCMON IF E DISK * D workdate S D datfmt(*MDY) c read edcmon 10 c *ISO move eddate workdate c z-add 1 x 1 0 c move *ON *INLR

                    Comment


                    • #11
                      Convert Date

                      Ron, I am sure I have recompiled the source. Recompile the program anyway. My eddate field is not defined in the program. Really? Then how did you get a clean compile? *grin* Chris

                      Comment


                      • #12
                        Convert Date

                        Chris, I recompiled the program after every change. I get a clean compile because the the file, EDCMON, with the field 'EDDATE', is externally defined. Why would you think it wouldn't compile? Ron

                        Comment


                        • #13
                          Convert Date

                          Ron, You said the field was not defined in the program. Of course it is! The external definition is pulled into the program on the compile. Otherwise you'd get a "7030" field not defined error. Your code should work. Maybe you need some PTF? Chris

                          Comment


                          • #14
                            Convert Date

                            I got the latest PTFs for V4R3.

                            Comment


                            • #15
                              Convert Date

                              FEDCMON IF E DISK * D workdate S D datfmt(*MDY) c read edcmon 10 c *ISO move eddate workdate c z-add 1 x 1 0 c move *ON *INLR --------- In this program, put a breakpoint on the first "move" (the one that moves eddate into workdate) and show view the contents of the following: *IN10 eddate workdate Then step to the next line. Tell us what line you are on. Show us the contents of the three fields again. Show us your joblog. Joe

                              Comment

                              Working...
                              X