Convert date from mmddyy to yyyymmdd?

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Convert date from mmddyy to yyyymmdd?

  • Creator
    Topic
  • #52680
    Sheetal Kairawala
    Participant

      Does anyone know how to convert date from mmddyy to yyyymmdd?

    Viewing 3 reply threads
    • Author
      Replies
      • #75094
        Jim Kosloskey
        Participant

          Sheetal,

          In Tcl,

          keylset stuff FABRICATE 1

             stuff is now a keyed list –> {FABRICATE 1}

          set new_date [convert_date -configure $stuff yd dt 8]

          Now new_date is converted.

          To see all the options of convert_date, in hictcl do help /hci/convert_date.

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

        • #75095
          Levy Lazarre
          Participant

            Another alternative, in Tcl, is to use a regular expression to transform the format “mmddyy” to the standard “mm/dd/yy” and call the “clock format” command on the resulting date string.

            Example, from the Tcl command prompt:

            Code:



            % set mydate 090711
            090711

            % regsub {(d{2})(d{2})(d{2})} $mydate {1/2/3} dt
            1

            % echo $dt
            09/07/11

            % set newdate [clock format [clock scan $dt] – format %Y%m%d]
            20090711

          • #75096
            Terry Kellum
            Participant

              Be careful when using “clock format”.  There are some weird corner cases in there that will ball you up.  Do a bunch of testing on your implementation.

            • #75097
              Levy Lazarre
              Participant

                Some of the issues with the “clock” command have been resolved in Tcl 8.5 and above, and now the “clock scan” command also has a “-format” option that makes programming easier.

                In the above code example, a space was accidently inserted between the ‘-‘ and the ‘format’ option. Evidently, it should read

                Code:



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

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