changing date format

Homepage Clovertech Forums Read Only Archives Cloverleaf Tcl Library changing date format

  • Creator
    Topic
  • #51476
    Kevin Crist
    Participant

    i have been fiddling with the clock command with no luck. in an xlate i am trying to format the date 201001111357 to 01/11/2010 1:57 PM. Any help would be appreciated.

    Thanks.

Viewing 2 reply threads
  • Author
    Replies
    • #70452

      Try this:

      Code:

      set input 201001111357
      set date [string range $input 0 7]
      set time [string range $input 8 end]
      set output [clock format [clock scan “$date $time”] -format “%D %R”]
      puts $output

      -- Max Drown (Infor)

    • #70453
      Steve Carter
      Participant

      I would suggest using a regsub to format the date into a format that can be scanned.  If the hour happens to be ’00’, you’ll get an error when trying to format it without the colon between the hours and minutes (and seconds, if included).

      hcitcl> set date “201001111357”

      hcitcl> regsub — {(d{8})(d{2})(d{2})} $date {1 2:3} newDate

      1

      hcitcl> puts $newDate

      20100111 13:57

      hcitcl> clock format [clock scan $newDate] -f {%m/%d/%Y %l:%M %p}

      01/11/2010  1:57 PM

      Here’s an example of a date that would fail without the colon between the hours and minutes:

      hcitcl>set newDate “20100111 0056”

      20100111 0056

      hcitcl>clock format [clock scan $newDate] -f {%m/%d/%Y %l:%M %p}

      Error: unable to convert date-time string “20100111 0056”

      hcitcl>set newDate “20100111 00:56”

      20100111 00:56

      hcitcl>clock format [clock scan $newDate] -f {%m/%d/%Y %l:%M %p}

      01/11/2010 12:56 AM

      This is a bug in the clock command.

      Hope this helps.

      Steve

    • #70454
      Chris Williams
      Participant

      It’s not necessarily a bug. It’s a documented feature.

      The clock command does its best to determine what you really want, but if you do not supply any punctuation to give it some guidance, it performs as documented. “0056” is invalid as a time component because clock requires six digits.

      From the clock documentation, the clock scan argument(s) must be:

      Quote:

      An ISO 8601 point-in-time specification, such as

      CCyymmddThhmmss,  where  T is the literal T,

      CCyymmdd  hhmmss, or

      CCyymmddThh:mm:ss.

      Note that only these three formats are accepted.  The command does not accept the full range of point-in-time  specifications  specified  in  ISO8601.

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

Forum Statistics

Registered Users
5,126
Forums
28
Topics
9,295
Replies
34,439
Topic Tags
287
Empty Topic Tags
10