Clock scan 24hr format

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Clock scan 24hr format

  • Creator
    Topic
  • #54021
    Femina Jaffer
    Participant

      Hello,

      Can someone help me with a preproc to convert the time from inbound OBR 7 field to military time format outbound.  For example, the iinbound format is 201401280127 and I need the outbound to be 201401281327 ?

      I have tried the following and it did not work:

      lassign $xlateInVals date

      set xlateOutVals [clock format [clock scan $date] -format %Y%m%d%H%M]

      Thank you so much,

      Femina

    Viewing 1 reply thread
    • Author
      Replies
      • #79899
        Levy Lazarre
        Participant

          Hello, Femina

          I am not sure one can properly convert to military time without an am/pm indicator. In your example, you seem to indicate that 0127 is an afternoon time and therefore 12 hours need to be added.

          Having said that, I am not aware of a ‘format’ option that will give you what you are looking for, but you could try something like this:

          Code:



          # get year, month, day
          set yearMonthDay [string range $date 0 7]

          # get the minutes
          set minutes [string range $date 10 11]

          # get the hours
          set hours [string range $date 8 9]

          # Convert the hours to military format. Add 12 hours only when indicated.
          # Note use of modulo operator to prevent going over 24 hours when adding
          set hours [expr $hours % 12 + 12]

          # Reassemble the date
          set newDate $yearMonthDay$hours$minutes

          # Output
          set xlateOutVals [list $newDate]

          I hope this helps.

        • #79900
          Femina Jaffer
          Participant

            Thanks Levy.  You are absolutely right, I really can’t do much unless I know if the time is in AM / PM.  Jim K, also pointed this out to me the other day.  Therefore, I have sent this back to the vendor.

            Thanks again, for your help and script.  I will probably need it at some point.

            Femina

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