Adding two 'times' togehter
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Adding two 'times' togehter
Hi,
i have two variables who represent duration of a song.
The one is for example: "00:03:06" and the other one: "00:02:15" and i am trying to add them together.
I have converted them both into "long time" and other formats and tried stuff like:
timeOne + timeTwo
put timeOne+timeTwo into ...
put sum(timeOne,timeTwo) into ....
add timeOne to timeTwo
but nothing seems to work for me... can anyone please help?
Rado
i have two variables who represent duration of a song.
The one is for example: "00:03:06" and the other one: "00:02:15" and i am trying to add them together.
I have converted them both into "long time" and other formats and tried stuff like:
timeOne + timeTwo
put timeOne+timeTwo into ...
put sum(timeOne,timeTwo) into ....
add timeOne to timeTwo
but nothing seems to work for me... can anyone please help?
Rado
Re: Adding two 'times' togehter
Hi rado,
we had a similar problem recently:
viewtopic.php?f=7&t=35882
Try this, tested and works:
You can also turn this into a function where you pass just tDate1 and tDate2 and it returns the sum of both times.
Drop a line if you need help with this!
Best
Klaus
we had a similar problem recently:
viewtopic.php?f=7&t=35882
Try this, tested and works:
Code: Select all
on mouseUp
put "00:03:25" into tDate1
put "00:02:15" into tDate2
## We need to subtract the whole day from the seconds or we will get something like:
## 81289:05:40 instead of the desired result: 00:05:40
put the date into tDatum
convert tDatum to seconds
convert tDate1 to seconds
convert tDate2 to seconds
## remove all days etc. and just leave HH:MM:SS
subtract tDatum from tDate1
subtract tDatum from tDate2
## Now do the math:
put tDate1 + tDate2 into tDate3
## Format as desired as SMPTE-lite:
put smpt_lite(tDate3)
end mouseUp
function smpt_lite tSecs
return format("%02d:%02d:%02d", tSecs div 3600, (tSecs mod 3600) div 60, tSecs mod 60)
end smpt_lite
Drop a line if you need help with this!
Best
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 9580
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Adding two 'times' togehter
Hi.
Fun, fun.
The "long time" is not really appropriate here. You have to deconstruct the string yourself. With the two times you posted in a field 1, and this In a button script:
I get 321 seconds.
Craig
Fun, fun.
The "long time" is not really appropriate here. You have to deconstruct the string yourself. With the two times you posted in a field 1, and this In a button script:
Code: Select all
on mouseUp
answer addSongLength(fld 1)
end mouseUp
function addSongLength var
set the itemDel to ":"
add item 3 of line 1 of var + item 3 of line 2 of var to totSeconds
add (item 2 of line 1 of var + item 2 of line 2 of var) * 60 to totSeconds
add (item 1 of line 1 of var + item 1 of line 2 of var) * 3600 to totSeconds
return totSeconds
end addSongLength
Craig
-
- VIP Livecode Opensource Backer
- Posts: 9580
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Adding two 'times' togehter
@Klaus.
What do you mean by "00:05:40"? That is not 321 seconds.
@ Rado.
Once we figure that out, do you need help to change to the "xx:yy:zz" format?
Craig
What do you mean by "00:05:40"? That is not 321 seconds.
@ Rado.
Once we figure that out, do you need help to change to the "xx:yy:zz" format?
Craig
-
- VIP Livecode Opensource Backer
- Posts: 9580
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Adding two 'times' togehter
Klaus.
I see, you used a slightly different time than I did.
I used what the OP posted
Craig
I see, you used a slightly different time than I did.
I used what the OP posted
Craig
Re: Adding two 'times' togehter
Hi Craig,
00:03:25 + 00:02:15 = 00:05:40, which resolves to 340 seconds.
Are we really using identical times?
Best
Klaus
even with my poor calculation skills I can see at a glance that this:
00:03:25 + 00:02:15 = 00:05:40, which resolves to 340 seconds.
Are we really using identical times?
Best
Klaus
Re: Adding two 'times' togehter
AHA!
Sorry, I wear glasses...
Sorry, I wear glasses...
Re: Adding two 'times' togehter
Thank you very much guys!
It works perfect with the code form Klaus.
Best regards,
Rado
It works perfect with the code form Klaus.
Best regards,
Rado