convert datetime from YYYYmmddhhmm to dd/mm/yyyy hh:mm

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf convert datetime from YYYYmmddhhmm to dd/mm/yyyy hh:mm

  • Creator
  • #49901
    Hongle Sun

    I use a tcl script and try to convert to with following statment

    #Collecteddate has value of 200801180954

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

    But it returms me an error message says ” unable to convert date-time string “200801180954”

    any ideal ? Thanks for the help

Viewing 1 reply thread
  • Author
    • #64043
      Charlie Bursell

      The scan expects a list of date and time or date alone.

      do this before you scan it

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

      Now it will scan

    • #64044
      John Mercogliano

      There is one problem with that way at least with QDX 5.2’s version of tcl.  If the original value is 200801180001 then the input would be

      20080118 0001

      But the output from clock gives you

      Fri Jan 18 01:00:00 EST 2008

      instead of

      Fri Jan 18 00:01:00 EST 2008

      This is a known bug in tcl that is not fixed until 8.5.  This affects all times between 0001 and 0059 as without the the colon it treats the value as an integer.

      It is safest to convert the time portion to HH:MM” class=”bbcode_url”>

      You can use this regsub command:

      regsub — {(d{8})(d{2})(d{2})} $Collecteddate {1 2:3} Collecteddate

      and of course

      regsub — {(d{8})(d{2})(d{2})(d{2})} $Collecteddate {1 2:3:4} Collecteddate

      if you have seconds. I used an if statement to choose which one.

      Now that we are on the subject, does anyone know of a way to do this with and without seconds in one regsub command 😀

      John Mercogliano
      Sentara Healthcare
      Hampton Roads, VA

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

Forum Statistics

Registered Users
Topic Tags