Date Format

  • Creator
    Topic
  • #48467
    Anonymous
    Participant

      I have had a request to take a date in this format:

      20040517123045  (YYYYMMDDHHMMSS)

      and convert it to this format:

      May-17-2004 12:30:45

      I’ve had some success doing it the other way around, but has anyone done it this way.  I was hoping there was a quick and dirty one or two liner that would do the trick.

      Thanks….

      Thomas G. Rioux

      trioux@tmh.tmc.edu

    Viewing 1 reply thread
    • Author
      Replies
      • #58704
        Rentian Huang
        Participant

          Tom, try this:

          Code:

          set d 20040517123045
          set mo [clock format [clock scan [crange $d 0 7]] -format “%b”]
          set out “${mo}-[crange $d 6 7]-[crange $d 0 3] [crange $d 8 9]:[crange $d 10 11]:[crange $d 12 13]”

          This is dirty but it works. Change %b to %B if you need full month name.

          Sam  8)

        • #58705
          Charlie Bursell
          Participant

            set olddate 20040517123045

            # Make it scanable – put a space between date and time

            # if the field has more than date

            if {[string length $olddate] > 8} {

                  regsub — {^d{8}} $olddate {& } olddate

            }

            set newdate [clock format [clock scan $olddate] -format

                 “%B-%d-%Y %T”]

            echo $newdate

            => May-17-2004 12:30:45

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