QT: How do I subtract clocktimes?

Devin Asay devin_asay at byu.edu
Thu Sep 20 14:37:35 EDT 2007


On Sep 20, 2007, at 11:16 AM, William de Smet wrote:

> Hi there all,
>
> I am subtracting some numbers and that is working ok with the  
> following code:
> put value (field "xt" - field "y") into fld "z"
>
> What If I want to use clock times like: 07.30 (seven thirty in the  
> morning) ?
> When I subract '16.00 - 07.30' I get '8.7' and I want it to be '08.30'
> So now Rev sees these numbers as decimal numbers.
>
> What code need I put in there to make it work?

William,

The easiest way to do time and date math is to convert the times or  
dates to seconds, do the calculations, then convert them back to time  
or date. So to subtract hours (This is assuming time format for the  
system is set properly; U.S. would use colons instead of dots):

  put "16.00" into t1
  put "7.30" into t2
  convert t1 to seconds
  convert t2 to seconds
  put t1 - t2 into tDiff
  put tDiff div (60*60) into tDiffHours
  put tDiff mod (60*60) into tDiffMins
  put tDiffHours & "." & tDiffMins into tTimeDiff

This is off the top of my head, not tested. But this approach should  
work just fine.

Regards,

Devin


Devin Asay
Humanities Technology and Research Support Center
Brigham Young University




More information about the use-livecode mailing list