Reformat dates

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Reformat dates

  • Creator
    Topic
  • #51707
    Mike Campbell
    Participant

      Not sure if the clock command can do this, or a basic TCL instream proc.

      I have an inbound field with ‘19780411’.  I need to write it out as

      ’04/11/1978′.  

      Version 5.7 on AIX.

      Thanks.

      Mike C.

    Viewing 15 reply threads
    • Author
      Replies
      • #71366
        Jim Kosloskey
        Participant

          Mike,

          The clock command:

          clock format -format %m/%d/%Y

          where is the date to be reformatted should do the trick.

          email: jim.kosloskey@jim-kosloskey.com 30+ years Cloverleaf, 61 years IT – old fart.

        • #71367
          Jim Kosloskey
          Participant

            Mike,

            I missed one command.

            Here is the correct command:

            clock format [clock scan ] -format %m/%d/%Y

            where is the date to be reformatted should do the trick.

            The clock scan which I omitted in the previous post converts the human redable date to an internal format that the clock format needs.

            email: jim.kosloskey@jim-kosloskey.com 30+ years Cloverleaf, 61 years IT – old fart.

          • #71368
            Mike Campbell
            Participant

              My problem is I have to reformat from the ccyymmdd that is coming in

              to be mm/dd/ccyy.  

              I’m not having any luck with doing that.

              set input $xlateInVals

              set date [string range $input 0 7]

              regsub {(d{4})(d{2})(d{2})} $date {2-3-1} newdate;

              set xlateOutVals $newdate

              I’m just tying to get the data switched around and can’t seem to get that to work. Seems the outval is the same as the inval…

            • #71369
              Michael Hertel
              Participant

                Change:

                set input $xlateInVals

                To:

                set input [lindex $xlateInVals 0]

                And

                Change:

                set xlateOutVals $newdate

                To:

                set xlateOutVals

              • #71370
                Mike Campbell
                Participant

                  I know I’m missing something really stoopid…

                  The input date is:  19870411

                  instream proc:

                  set input [lindex $xlateInVals 0]

                  set indate [string range $input 0 7]

                  regsub {(d{4})(d{2})(d{2})} $indate {2-3-1} newdate;

                  set xlateOutVals

                    OutVals still is 19780411.

                    Trying to get to 04111978 initially, then 04/11/1978 finally.  Figured I’d try to at least reformat the date then work on the ‘/’

                • #71371
                  Michael Hertel
                  Participant

                    Your code works for me:

                    hcitcl>set datelist

                  • 19870411

                    hcitcl>set input [lindex $datelist 0]

                    19870411

                    hcitcl>set indate [string range $input 0 7]

                    19870411

                    hcitcl>regsub {(d{4})(d{2})(d{2})} $indate {2-3-1} newdate

                    1

                    hcitcl>set xlateOutVals

                      04-11-1987

                      hcitcl>

                      Try adding echo statements:

                      echo >$xlateInVals<

              • #71372
                Mike Campbell
                Participant

                  Okay…that is really odd.

                  The echo from the xlate does show:

                  19870411

                  04-11-1987

                  and yet the value written out is the original.  Thanks Mike for the echo idea.  Now…just to figure out the rest!  

                  I’ll post what the outcome is…

                • #71373
                  James Cobane
                  Participant

                    Mike,

                    Take a look at the field definition of the outbound field that you are mapping to. Is it a date field(?), and if so look at the format specified for that date field; it may be formatting it based on the outbound record definition.

                    Hope this helps.

                    Jim Cobane

                    Henry Ford Health

                  • #71374
                    Mike Campbell
                    Participant

                      The output is actually a VRL file, and all fields are set as strings.

                      Min. width of 1

                      Max. width of -1

                    • #71375
                      Russ Ross
                      Participant

                        Since you have debugged via an echo from within your xlt proc and that shows everything to be fine, try echoing out from the xlate right after the reformatted date is copied to confirm the copy statement is or isn’t giving the desired reformatted date.

                        If this debug echo shows the correct outcome, then that would make me wonder if a subsequent copy might exist in your Xlate that is overwriting the desired reformatted string.

                        Another thought to be careful about is that if iterations are involved, be sure your copy path isn’t hardcoded and has the necessary iteration variable in the copy path defined in the xlate.

                        Russ Ross
                        RussRoss318@gmail.com

                      • #71376
                        Mike Campbell
                        Participant

                          I have met the enemy..and he is me…

                          We have a little ‘debug’ proc and that was over-riding the changes.

                          😳

                          Now…to reformat with a ” in stead of the ‘-‘.

                        • #71377
                          Michael Hertel
                          Participant

                            Been there, done that.  😛

                          • #71378
                            Mike Campbell
                            Participant

                              So, if you ‘escape’ the slash, the date works as desired…

                              regsub {(d{4})(d{2})(d{2})} [lindex $indate 0] {2\3\1} newdate;

                              input:  19741010

                              output:  10101974

                              Again, thanks to all for the great hints and help.

                            • #71379
                              Michael Hertel
                              Participant

                                Didn’t you want forward slashes instead of backslashes?

                              • #71380
                                Michael Hertel
                                Participant

                                  You can do this in one line. See Jim’s previous example.

                                  hcitcl>set xlateOutVals

                                    ] -format %m/%d/%Y]]

                                    07/08/2004

                                    hcitcl>

                                  1. #71381
                                    Mike Campbell
                                    Participant

                                      Yes…the slashes were wrong.  Figured that out…

                                    • Viewing 15 reply threads
                                      • The forum ‘Cloverleaf’ is closed to new topics and replies.