Date format

Homepage Clovertech Forums Cloverleaf Date format

  • Creator
    Topic
  • #118365
    Collin Praster
    Participant

    Hello I am looking for some assistance on a date format

    I have a date coming in on 1(0).0(0).PID(0).#7(0).[0]

    its coming in as 19990101

    I need to change it to month day year and add  /

     

    so  01/01/1999

     

    Thank you

Viewing 5 reply threads
  • Author
    Replies
    • #118366
      Boris Perov
      Participant

      set myDate [lindex $xlateInVals 0]

      set xlateOutVals [clock format $myDate -format “%m/%d/%Y”]

      • #118373
        Boris Perov
        Participant

        Ha!  forgot to copy and paste the clock scan command…  Looks like Tipu gave you the more “complete” answer.  Thanks 😉

    • #118367
      Jim Kosloskey
      Participant

      If in an Xlate and no Tcl:

      Use the STRING Action substring function to extract the ccyy, mm, and dd elements to temp variables.

      Then use a CONCAT Action to combine the respective temp variables using / as the separator.

      If you are going to use Tcl don’t forget the xlateOut lists (vals, etc) are LISTS and should be treated as such.

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

    • #118368
      Tipu Razaq
      Participant

      If you want a one-liner and a more thorough attempt, it will be like so:

      lset xlateOutVals 0 [clock format [clock scan [lindex $xlateInVals 0] -format “%Y%d%m”] -format “%m/%d/%Y”]

       

      You really should tell TCL how the incoming date is formatted, otherwise it’ll take a best guess which may result in incorrect output data and/or just error entirely.

      • #118375
        Collin Praster
        Participant

        Hello I tired your solution and received this error

         

        MESSAGE 1
        Tcl callout error
        lset xlateOutVals 0 [clock format [clock scan [lindex $xlateInVals 0] -format “%Y%d%m”] -format “%m/%d/%Y”]:

        errorCode: NONE

        errorInfo:
        bad switch “-format”: must be -base or -gmt
        while executing
        “clock scan [lindex $xlateInVals 0] -format “%Y%d%m””
        invoked from within
        “clock format [clock scan [lindex $xlateInVals 0] -format “%Y%d%m”] -format “%m/%d/%Y””
        invoked from within
        “lset xlateOutVals 0 [clock format [clock scan [lindex $xlateInVals 0] -format “%Y%d%m”] -format “%m/%d/%Y”]”
        <End of errorInfo>

      • #118377
        Tipu Razaq
        Participant

        Interesting. Works when I try it.

        Which version of TCL are you using? ‘info patchlevel’ command should tell you.

        I think the format option was added in 8.5

         

        I also noticed a mix up in the original code snippet. I’m assuming the date is coming in the following format: YYYYMMDD and you want it turned into MM/DD/YYYY

        Updated snippet below:

        lset xlateOutVals 0 [clock format [clock scan [lindex $xlateInVals 0] -format %Y%m%d] -format %m/%d/%Y]

      • #118379
        Collin Praster
        Participant

        I am still using cloverleaf 5.8 so not sure what version that is using

      • #118380
        Tipu Razaq
        Participant

        Makes sense. Your version of TCL is too old.

        You can try this. It’s definitely not ideal. It’s just manipulating the string by extracting the YEAR, MONTH, DAY and creating a new string MM/DD/YYYY

         

        Hopefully it’ll work with your version of TCL

        Incoming string format YYYYMMDD

        Output string format MM/DD/YYYY

        lset xlateOutVals 0 [string cat [string range [lindex $xlateInVals 0] 4 5] “/” [string range [lindex $xlateInVals 0] 6 7] “/” [string range [lindex $xlateInVals 0] 0 3] ]

      • #118381
        Collin Praster
        Participant

        Thank you so much for the help but I still got another error, I am sure do to my old tcl

         

        MESSAGE 1
        Tcl callout error
        lset xlateOutVals 0 [string cat [string range [lindex $xlateInVals 0] 4 5] “/” [string range [lindex $xlateInVals 0] 6 7] “/” [string range [lindex $xlateInVals 0] 0 3] ]:

        errorCode: NONE

        errorInfo:
        bad option “cat”: must be bytelength, compare, equal, first, index, is, last, length, map, match, range, repeat, replace, tolower, toupper, totitle, trim, trimleft, trimright, wordend, or wordstart
        while executing
        “string cat[string range [lindex $xlateInVals 0] 4 5] “/” [string range [lindex $xlateInVals 0] 6 7] “/” [string range [lindex $xlateInVals 0] …”
        invoked from within
        “lset xlateOutVals 0 [string cat[string range [lindex $xlateInVals 0] 4 5] “/” [string range [lindex $xlateInVals 0] 6 7] “/” [string range [li…”
        <End of errorInfo>

      • #118383
        Tipu Razaq
        Participant

        Hmmm

         

        Try this

         

        lset xlateOutVals 0 “[string range [lindex $xlateInVals 0] 4 5]/[string range [lindex $xlateInVals 0] 6 7]/[string range [lindex $xlateInVals 0] 0 3]”

      • #118384
        Collin Praster
        Participant

        You are awesome!!

        Thank you so much for the assistance!!

      • #118385
        Tipu Razaq
        Participant

        No problem! Glad it worked!

    • #118369
      Paul Bishop
      Participant

      you can do this with a code snippet in the translate.  couple of different ways – first is to string range each portion out, then rebuild it with the slashes.  Second way is to use clock scan/clock format.

      clock scan example
      lassign $xlateInVals in_pid_7_0

      set out_pid_7_0 [clock format [clock scan $in_val -format %Y%m%d] -format %m/%d/%Y]

      set xlateOutVals

        string range example
        lassign $xlateInVals in_pid_7_0

        set out_pid_7_0 “[string range $in_pid_7_0 4 5]/[string range $in_pid_7_0 6 7]/[string range $in_pid_7_0 0 3]”

        set xlateOutVals

           

          formatting is weird – removed my “list $out_pid_7_0” within brackets after the “set XlateOutVals”

          • This reply was modified 3 years, 9 months ago by Paul Bishop.

          Paul Bishop
          Carle Foundation Hospital
          Urbana, IL

        1. #118376
          Collin Praster
          Participant

          Hello I tried Tipu’s solution but I received the below error

          MESSAGE 1
          Tcl callout error
          lset xlateOutVals 0 [clock format [clock scan [lindex $xlateInVals 0] -format “%Y%d%m”] -format “%m/%d/%Y”]:

          errorCode: NONE

          errorInfo:
          bad switch “-format”: must be -base or -gmt
          while executing
          “clock scan [lindex $xlateInVals 0] -format “%Y%d%m””
          invoked from within
          “clock format [clock scan [lindex $xlateInVals 0] -format “%Y%d%m”] -format “%m/%d/%Y””
          invoked from within
          “lset xlateOutVals 0 [clock format [clock scan [lindex $xlateInVals 0] -format “%Y%d%m”] -format “%m/%d/%Y”]”
          <End of errorInfo>

        2. #118389
          Charlie Bursell
          Participant

          Why jump through the hoops of tearing the string apart and then put it back together?  The clock command was designed for cases like this.  Boris was on the right track but his command was incomplete.

          Try

          set myDate [lindex $xlateInVals 0]
          set xlateOutVals

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

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

        Forum Statistics

        Registered Users
        5,129
        Forums
        28
        Topics
        9,301
        Replies
        34,447
        Topic Tags
        288
        Empty Topic Tags
        10