Page 2 of 2

Re: Subtract two 24 hour times

Posted: Wed Jul 11, 2012 7:41 pm
by LittleGreyMan
Just tested it, with 3 fields: "Start", "Stop" and "Duration", plus a "Compute" button with this script:

Code: Select all

on mouseUp
   --   get the colon separated values
   set the itemDelimiter to colon
   put fld "Start" into tStart
   put fld "Stop" into tStop
   --  convert into minutes
   put item 1 of tStart *60 + item 2 of tStart into tStart
   put item 1 of tStop *60 + item 2 of tStop into tStop
   -- solve cross-midnight issue by adding 24H to tStop
   if tStart > tStop then add 24*60 to tStop
   put tStop-tStart into tDuration
   --  convert the result in minutes into decimal hour and round to 1/10
   set the numberFormat to "0.0"
   put round (tDuration/60,1) into tDuration
   put tDuration into fld "Duration"
end mouseUp
No error checking, this raw script has to be improved in order to be bullet-proof. The syntax is perhaps not the best one (used to another x-talk tool). Some operations broken in several lines for clarity (no tDuration variable is necessary):

Code: Select all

put round ((tStop-tStart)/60,1) into fld "Duration"
Let us know if it suits your need.

HTH

Re: Subtract two 24 hour times

Posted: Thu Jul 12, 2012 1:46 am
by sxpapado
Thanks Didier and all that helped here. :D

Re: Subtract two 24 hour times

Posted: Thu Jul 12, 2012 1:56 am
by sxpapado
Just tested it. works great. Thanks again to all.

Best Regards

Re: Subtract two 24 hour times

Posted: Thu Jul 12, 2012 8:54 am
by LittleGreyMan
You're welcome. Glad it helped.