TCL scrip for changing date from MM/DD/YYYY to YYYYMMDD

Clovertech Forums Read Only Archives Cloverleaf Tcl Library TCL scrip for changing date from MM/DD/YYYY to YYYYMMDD

  • Creator
    Topic
  • #55421
    stephen fouche
    Participant

      # format into hl7 date format

      lassign $xlateInVals date

      set date [split $date /]

      lassign $date m d y

      set xlateOutVals

        #set xlateOutVals

    Viewing 4 reply threads
    • Author
      Replies
      • #85264
        Jim Kosloskey
        Participant

          If one is at Cloverleaf release 6.1.1 or later, one can use thee Xlate STRING Action (range function) to pull out the pieces of the date (after all the pieces are always in the same place).

          Then using the CONCAT Action combine the pieces back together as needed.

          Could be used if the reverse is true (CCYYMMDD to MM/DD/CCYY).

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

        • #85265
          Sean Farley
          Participant

            You have already broken the date into a list.  Each element in the list is part of the new date format that you need.  I think you can just change your last line to:

            set xlateOutVals “[lindex $date 2][lindex $date 0][lindex $date 1]”

            That should put it in YYYYMMDD format.  I hope that helps.

          • #85266
            Charlie Bursell
            Participant

              why not simply?

              set dt 06/10/2017

              set newdt [clock format [clock scan $dt] -format %Y%m%d]

            • #85267
              Sean Farley
              Participant

                Charlie’s answer is best!  I wasn’t sure if “clock scan” liked the MM/DD/YYYY” format, but I verified that it does in fact work.

                set xlateOutVals [clock format [clock scan $date] -format “%Y%m%d”]

              • #85268
                Mark Thompson
                Participant

                  Not sure how Charlie let this slip through – xlateOutVals should always be a list.  In this particular case it doesn’t matter, but best practice would be:

                  set xlateOutVals

                    -format “%Y%m%d”]]

                    - Mark Thompson
                    HealthPartners

                Viewing 4 reply threads
                • The forum ‘Tcl Library’ is closed to new topics and replies.