Need to Convert OBX:5 value YYYYMMDDHHMMSS into MM/DD/YYYY HH:MM

Clovertech Forums Cloverleaf Need to Convert OBX:5 value YYYYMMDDHHMMSS into MM/DD/YYYY HH:MM

  • Creator
    Topic
  • #121275
    Steve Simmons
    Participant

      Need to convert the Convert OBX:5 value YYYYMMDDHHMMSS into MM/DD/YYYY HH:MM.

      Trying to use Xlate with the TCL.

      Not having very much luck.

      Thanks.

    Viewing 6 reply threads
    • Author
      Replies
      • #121276
        Paul Bishop
        Participant

          There are multiple ways to do it.  Off the top of my head, if you know that the input will ALWAYS be in that format (YYYYMMDDHHMMSS), then you can use the clock command (copy pre-proc):
          <pre>lassign $xlateInVals in_obx_5
          set out_obx_5 [clock format [clock scan $in_obx_5 -format “%Y%m%d%H%M%S”] -format “%m/%d/%Y %H:%M”]
          set xlateOutVals

            </pre>
            The problem with using the clock command is that if it doesn’t match the input format on the scan portion, it will fail.

            Another way of doing it is to use string range commands to pull out each element of the date and time, and then set the output variable to what you need it to be.

            There is also the format command, but I always have to look up all the options for it.  Those are the first ones I thought of off the top of my head, but I’m sure there are many other ways as well.

            I would put coding before it to verify it matches the input format you are expecting (length, all numeric, etc).

            Hope this helps!

            Paul Bishop
            Carle Foundation Hospital
            Urbana, IL

          1. #121277
            David Barr
            Participant

              Probably a regsub is the easiest way to do this. Something like:

              
              set xlateOutVals [list [regsub {(….)(..)(..)(..)(..)(..)} [lindex xlateInVals 0] {\2/\3/\1 \4:\5}]]
              
              
              • This reply was modified 8 months, 3 weeks ago by David Barr.
              • This reply was modified 8 months, 3 weeks ago by David Barr.
            • #121280
              Keith McLeod
              Participant

                Try this:

                regsub — {(\d{8})(\d{4,6})} [lindex $xlateInVals 0] {\1 \2} dt

                set xlateOutVals

                  -format “%m/%d/%Y %H:%M:%S”]]

                  Example:

                  hcitcl>set xlateInVals 20240402120000
                  20240402120000
                  hcitcl>regsub — {(\d{8})(\d{4,6})} [lindex $xlateInVals 0] {\1 \2} dt
                  1
                  hcitcl>echo $dt
                  20240402 120000
                  set xlateOutVals

                    -format “%m/%d/%Y %H:%M:%S”]]
                    {04/02/2024 12:00:00}

                    Hope this helps…

                    • This reply was modified 8 months, 3 weeks ago by Keith McLeod.
                    • This reply was modified 8 months, 3 weeks ago by Keith McLeod.
                  1. #121283
                    Steve Simmons
                    Participant

                      Thanks Paul, that worked great.

                      Yes, the input will always be the same.

                    • #121284
                      Keith McLeod
                      Participant

                        hcitcl>set xlateInVals 20240402120000
                        20240402120000

                        hcitcl>regsub — {(\d{8})(\d{4,6})} [lindex $xlateInVals 0] {\1 \2} dt
                        1

                        hcitcl>echo $dt
                        20240402 120000

                        hcitcl>set xlateOutVals

                          -format “%m/%d/%Y %H:%M:%S”]]
                          {04/02/2024 12:00:00}

                          • This reply was modified 8 months, 3 weeks ago by Keith McLeod.
                        1. #121286
                          Jim Kosloskey
                          Participant

                            And… if you are on release 6.0 or later of Cloverleaf, and you do not want to use Tcl:

                            Use the STRING Action functions to break out the Source unformatted Date/Time:

                            STRING XlateStrSubString 0 3 –> @CCYY

                            STRING XlateStrSubString 4 5 –> @MM

                            STRING XlateStrSubString 6 7 –> @DD

                            STRING XlateStrSubString  8 9 –> @HH

                            STRING XlateStrSubString  10 11 –> @MIN

                            Then CONCAT together with separators:

                            @MM         —> Destination

                            =/

                            @DD

                            =/

                            @CCYY

                            =

                            @HH

                            =:

                            @MIN

                            email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

                          • #121287
                            Jim Vilbrandt
                            Participant

                              Here’s one more:
                              <pre>set inStr [lindex $xlateInVals 0]
                              if [clength $inStr] {
                              set obStr [fmtclock [clock scan $inStr -format %Y%m%d%H%M%S] “%m/%d/%Y %H:%M:%S”]
                              xpmstore $xlateId [lindex $xlateOutList 0] c $obStr
                              }</pre>

                          Viewing 6 reply threads
                          • You must be logged in to reply to this topic.