Subtract two 24 hour times

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

LittleGreyMan
Posts: 49
Joined: Sat Jun 16, 2012 7:57 pm

Re: Subtract two 24 hour times

Post by LittleGreyMan » Wed Jul 11, 2012 7:41 pm

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
Best regards,

Didier

sxpapado
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10
Joined: Tue Oct 04, 2011 5:54 pm

Re: Subtract two 24 hour times

Post by sxpapado » Thu Jul 12, 2012 1:46 am

Thanks Didier and all that helped here. :D

sxpapado
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10
Joined: Tue Oct 04, 2011 5:54 pm

Re: Subtract two 24 hour times

Post by sxpapado » Thu Jul 12, 2012 1:56 am

Just tested it. works great. Thanks again to all.

Best Regards

LittleGreyMan
Posts: 49
Joined: Sat Jun 16, 2012 7:57 pm

Re: Subtract two 24 hour times

Post by LittleGreyMan » Thu Jul 12, 2012 8:54 am

You're welcome. Glad it helped.
Best regards,

Didier

Post Reply