Date Formatting Problem

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Date Formatting Problem

  • Creator
    Topic
  • #50344
    David Harrison
    Participant

      In an Xlate, I want to convert a date where the day and month have no leading zero. As an example, today is presented as 3/10/2008.

      I would like to know the best way to convert this to the format CCYYMMDD.

      Thanks,

      Dave

    Viewing 4 reply threads
    • Author
      Replies
      • #65699
        Charlie Bursell
        Participant

          set dt 3/10/2008

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

           => 20080310

        • #65700
          David Harrison
          Participant

            That simple! Many thanks.

          • #65701
            Gary Atkinson
            Participant

              If I had date that also included the time, how would I use clock to just return the date?  For example my date/time value is: 20080921194800 and I want to return only 09/21/2008.

            • #65702
              Rob Abbott
              Keymaster

                read up on “clock scan” in tclhelp.  It accepts several formats.

                In this case you would only want to send teh first 8 digits of your timestamp to clock scan in the code above:

                set dt [string range $datetime 0 7]

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

                Rob Abbott
                Cloverleaf Emeritus

              • #65703
                Gary Atkinson
                Participant

                  Thanks Rob.

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