Re: Subtract two 24 hour times
Posted: Wed Jul 11, 2012 7:41 pm
Just tested it, with 3 fields: "Start", "Stop" and "Duration", plus a "Compute" button with this script:
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):
Let us know if it suits your need.
HTH
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 mouseUpCode: Select all
put round ((tStop-tStart)/60,1) into fld "Duration"HTH