Date/Time formatting

Clovertech Forums Read Only Archives Cloverleaf General Date/Time formatting

  • Creator
    Topic
  • #55374
    Omair Haq
    Participant

      Hi everyone,

      I wanted to format the data/time in a discrete filed as follow in the Xlate:

      Source is sending as: 201704270933

      I want o format as:

      mm/dd/yyyy HH:MM (04/27/2017 9:33).

      I just need a fragment of tcl code which I can put it in my Xlate for formatting. I’m sure this is very commonly done and need your assistance. Thanks much.

    Viewing 12 reply threads
    • Author
      Replies
      • #85110
        Sean Farley
        Participant

          You should be able to use something like the following:

          set sDate “201704270933”

          set xlateOutVals [clock format [clock scan $sDate -format “%Y%m%d%H%M” ] -format “%m/%d/%Y %H:%M”]

          This will turn 201704270933 into 04/27/2017 09:33.

          Thanks.

        • #85111
          Omair Haq
          Participant

            Thanks. Can I just omit the sDate variable? -Omair

            set sDate “201704270933”

            set xlateOutVals [clock format [clock scan $sDate -format “%Y%m%d%H%M” ] -format “%m/%d/%Y %H:%M”]

          • #85112
            Keith McLeod
            Participant

              Change it to:

              set sDate [lindex $xlateInVals 0]

              regsub — {(d{8})(d+)} $sDate {1 2} sDate

              And then the rest from previous post.

              Happy motoring!!!

            • #85113
              Omair Haq
              Participant

                Thank you all very much. We miss you Keith:)

              • #85114
                Omair Haq
                Participant

                  I figured it out; it was an issue with my XLATE.

                • #85115
                  Robert Milfajt
                  Participant

                    We miss you too Keith.

                    Robert Milfajt
                    Northwestern Medicine
                    Chicago, IL

                  • #85116
                    Lina Patel
                    Participant

                      Hello,

                      tcl proc current date is:

                      2017-11-02 14:59:31

                      Needs to be:

                      yyyymmddhhmiss

                      Thank you for your assistance.

                      Lina

                    • #85117
                      Keith McLeod
                      Participant

                        clock format [clock scan “2017-11-02 14:59:31”] -format “%Y%m%d%H%M%S”

                        Example:

                        hcitcl>clock format [clock scan “2017-11-02 14:59:31”] -format “%Y%m%d%H%M%S”

                        20171102145931

                        Hope this helps….I ran from the hcitcl command line

                      • #85118
                        Keith McLeod
                        Participant

                          You can use

                          clock format [clock scan now] -format “%y%m%d%H%M%S”

                          for the current time….

                        • #85119
                          Lina Patel
                          Participant

                            Absolutely – Hugh help!

                            Works using command line

                            hcitcl>clock format [clock scan “2017-11-02 14:59:31”] -format “%Y%m%d%H%M%S”

                            20171102145931

                            Does not work when plugging in variable in tclproc – no errors

                            clock format [clock scan $actweightdt] -format “%Y%m%d%H%M%S”

                            2017-11-02 14:59:31

                          • #85120
                            Keith McLeod
                            Participant

                              What is your source data for the actweighdt variable?

                              hcitcl>set actweighdt “2017-11-02 14:59:31”

                              2017-11-02 14:59:31

                              hcitcl>clock scan $actweighdt

                              1509649171

                              hcitcl>clock format [clock scan $actweighdt] -format “%Y%m%d%H%M%S”

                              20171102145931

                              If your date starts out like 20171102145931, you may need to do something like:

                              hcitcl>set actweighdt 20171102145931

                              20171102145931

                              hcitcl>regsub — {(d{8})(d+)} $actweighdt {1 2} new_actweighdt

                              1

                              hcitcl>clock format [clock scan $new_actweighdt] -format “%Y%m%d%H%M%S”

                              20171102145931

                              May if I understood what you are actually trying to accomplish and what you are working with for data, I could explain better.  The regsub command split the date and time into “20171102 145931” to better satisfy the clock scan command.  You may also want to google the tcl clock commands.  Hope this helps…

                            • #85121
                              Lina Patel
                              Participant

                                Below worked:

                                            set new_actweightdt “”

                                              set new_actweightdt [clock format [clock scan $actweightdt] -format “%Y%m%d%H%M%S”]

                                   

                                Thank you again for all your help!

                                Lina 🙂

                              • #85122
                                David Barr
                                Participant

                                  These commands all do the same thing:

                                  set foo “”; clock scan $foo

                                  clock scan “”

                                  clock scan now

                                  They convert a time into seconds since the epoch. But if you’re just trying to get the current time in seconds since the epoch it makes more sense just to say “clock seconds”, i.e. clock format [clock seconds] -format “%Y%m%d%H%M%S”.

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