Tcl to calculate date/time difference

Homepage Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Tcl to calculate date/time difference

  • Creator
    Topic
  • #50114
    Rentian Huang
    Participant

    Greetings Cloverleafers!!!

    I am trying to get the time length between two date/time. Ie. 200806131300 and 200806162359, the result is 3 days 10 hours and 59 min. I tried to do it via the MATH action in Xlate but it did not work.

    Anyone have a handy tcl to it?

    Thanks in advance!

    Sam   8)

Viewing 5 reply threads
  • Author
    Replies
    • #64932
      Glenn Friedenreich
      Participant

      Use the tcl clock command.  (Do the math with the output of clock scan, and covert back to readable format with clock format.)

      See http://tmml.sourceforge.net/doc/tcl/clock.html#SECTid81dd9d8

      – Glenn

    • #64933
      John Mercogliano
      Participant

      Glenn,

      John Mercogliano
      Sentara Healthcare
      Hampton Roads, VA

    • #64934
      Russ Ross
      Participant

      Here is a tangible example that might be similar enough to help you get going.

      In this esample, I kill a message if the time stamp (TS) stored in AIL-6 of a SIU scheduling message is older than 6 hours when it hits cloverleaf.

      The URL to the entire trxid proc can be found at

      http://clovertech.infor.com/viewtopic.php?t=1562&” class=”bbcode_url”>http://clovertech.infor.com/viewtopic.php?t=1562&

      Here is the code snippet from ( trxid_SIU_rxtfc.tcl ) that illustrates how I call the proc ( oth_chk_time_span.tcl ) that does the acutal work of figuring out the time difference:

      [code]

      Russ Ross
      RussRoss318@gmail.com

    • #64935
      Rentian Huang
      Participant

      Waw, thanks for all your helps and input, it’s helpful, I will take some time to investigate them.

      Good day!

      8)

    • #64936
      Keith McLeod
      Participant

      How about something like this:

      set timediff [expr [clock scan “20080616T235900”]-[clock scan “20080613T130000”]]

      set days [expr $timediff/86400]

      set hours [expr $timediff%86400/3600]

      set minutes [expr $timediff%86400%3600/60]

      echo “$days days $hours hours $minutes min.”

      Notice the ‘T’ between the date and the time…. I am sure you can do an insert of some sort….  Also the time must have hhmmss in it for clock scan to work….The results:

      3 days 10 hours 59 min.

      This was quick and dirty so I hope I didn’t miss anything… Happy Motoring….

    • #64937
      Rentian Huang
      Participant

      Hi Keith,

      Your method fits my requirement well, and it is handy and small. Thanks for all your input! I really appreciated them!!!

      Sam  8)

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

Forum Statistics

Registered Users
5,115
Forums
28
Topics
9,290
Replies
34,422
Topic Tags
286
Empty Topic Tags
10