Page 1 of 1

Time calculations

Posted: Mon Jun 22, 2015 7:53 pm
by mahendra
Hi I am trying to find a routine/solution to add minutes to time to create reservation slots. e.g..

Res start time of 07:00
Res end time of 21:00
Duration of res slot 40 minutes

So I want to add 40minutes to 07:00 and create reservation slots in 40 minute increments to 21:00

How can I do this?

Re: Time calculations

Posted: Mon Jun 22, 2015 8:23 pm
by bn
Hi Mahendra,

welcome to the forum

look at this piece of code and please look up the relevant keywords in the dictionary for an explanation

make 1 field and 1 button; the script of the button:

Code: Select all

on mouseUp
   put 21 - 7 into tHours
   put tHours * 60 into tMinutes
   put tMinutes div 40 into tIntervalNo -- the number of 40 minutes intervals that fit into the time from 7 to 21 hours
   
   set the twelveHourTime to false -- no "am" or "pm" but in 24 hour format
   
   put "7:00" into tStartTime
   convert  tStartTime from short english time to dateItems
   
   put tStartTime into tCurrTime -- copy the dateItems to new variable that will be turned into time
   convert tCurrTime to short time -- here dateItems in tCurrTime are converted to time
   put tCurrTime & cr after tCollect -- collect the times
   
   
   
   repeat tInterValNo
      add 40 to item 5 of tStartTime -- add to dateItems
      put tStartTime into tCurrTime -- again transfer to variable
      convert tCurrTime to short time -- that will be converted to the time
      put tCurrTime & cr after tCollect
   end repeat
   
   delete byte - 1 of tCollect -- delete last return
   
   put tCollect into field 1
   
end mouseUp
Kind regards

Bernd

Re: Time calculations

Posted: Mon Jun 22, 2015 10:22 pm
by dunbarx
Hi.

I prefer a standardized time gadget. Try both of these in a button. They will yield a time that is 40 minutes after you click the button. The starting time, and any number of intervals, can then be easily incorporated into the code:

Code: Select all

on mouseUp
   get the time
   convert it to dateItems
   add 40 to item 5 of it
   convert it to short time
   answer it
end mouseUp

on mouseUp
   get the time
   convert it to seconds
   add 2400 to it
   convert it to short time
   answer it
end mouseUp
Just to show that LC has a wealth of tools for this sort of thing. Which way you do it is a matter of personal style.

Craig Newman

Re: Time calculations

Posted: Tue Jun 23, 2015 11:30 am
by mahendra
Absolutely awesome :D Thank you for the swift replies.