[HC] Date and Time calculations

(Msg 1 of 5)

ka4hjh <ka4hjh@[redacted].com>

Thursday, 15-Feb-2018 20:05 GMT

I'm writing a simple stack to keep track of battery life for my iDevices. I need a function that can calculate the elapsed time between two timestamps (date and time) with the difference in H:M:S or even just hours. I'm sure I could figure it out and reinvent the wheel in the process but I figured I'd ask first.

I plan on converting my stack to LiveCode at some point. Info on how it's done in LC would be helpful as well. I looked at the forums and the dictionary but my eyes started to glaze over... Too much information.

Terry Bowman, KA4HJH

"The Mac Doctor"

I plan on converting my stack to LiveCode at some point. Info on how it's done in LC would be helpful as well. I looked at the forums and the dictionary but my eyes started to glaze over... Too much information.

Terry Bowman, KA4HJH

"The Mac Doctor"

[HC] Date and Time calculations

(Msg 2 of 5)

m.schonewille <m.schonewille@[redacted].com>

Thursday, 15-Feb-2018 21:15 GMT

You're looking for this script:

on mouseUp

put timeDif(cd fld 1,cd fld 2) into cd fld 3

end mouseUp

function timeDif theDate1,theDate2

convert theDate2 to seconds

convert theDate1 to seconds

put theDate2 - theDate1 into myDif

put myDif div (24*60*60) into myDays

put myDif mod (24*60*60) into myRemainder

put myRemainder div (60*60) into myHours

put myRemainder mod (60*60) into myRemainder

put myRemainder div 60 into myMinutes

put myRemainder mod 60 into mySeconds

return myDays && myHours && myMinutes && mySeconds

end timeDif

It works in LiveCode and HyperCard, possibly even with SuperCard, but I

don't have a Mac at my disposal right now to test that.

This script works, but I'm not sure how DST affects it.

Kind regards,

Mark Schonewille

http://economy-x-talk.com

https://www.facebook.com/marksch

Buy the most extensive book on the

LiveCode language:

http://livecodebeginner.economy-x-talk.com

Op 15-Feb-18 om 21:05 schreef KA4HJH ka4hjh@[redacted].com[HyperCard]:

> I'm writing a simple stack to keep track of battery life for my iDevices. I need a function that can calculate the elapsed time between two timestamps (date and time) with the difference in H:M:S or even just hours. I'm sure I could figure it out and reinvent the wheel in the process but I figured I'd ask first.

>

> I plan on converting my stack to LiveCode at some point. Info on how it's done in LC would be helpful as well. I looked at the forums and the dictionary but my eyes started to glaze over... Too much information.

>

>

> Terry Bowman, KA4HJH

> "The Mac Doctor"

>

>

>

>

on mouseUp

put timeDif(cd fld 1,cd fld 2) into cd fld 3

end mouseUp

function timeDif theDate1,theDate2

convert theDate2 to seconds

convert theDate1 to seconds

put theDate2 - theDate1 into myDif

put myDif div (24*60*60) into myDays

put myDif mod (24*60*60) into myRemainder

put myRemainder div (60*60) into myHours

put myRemainder mod (60*60) into myRemainder

put myRemainder div 60 into myMinutes

put myRemainder mod 60 into mySeconds

return myDays && myHours && myMinutes && mySeconds

end timeDif

It works in LiveCode and HyperCard, possibly even with SuperCard, but I

don't have a Mac at my disposal right now to test that.

This script works, but I'm not sure how DST affects it.

Kind regards,

Mark Schonewille

http://economy-x-talk.com

https://www.facebook.com/marksch

Buy the most extensive book on the

LiveCode language:

http://livecodebeginner.economy-x-talk.com

Op 15-Feb-18 om 21:05 schreef KA4HJH ka4hjh@[redacted].com[HyperCard]:

> I'm writing a simple stack to keep track of battery life for my iDevices. I need a function that can calculate the elapsed time between two timestamps (date and time) with the difference in H:M:S or even just hours. I'm sure I could figure it out and reinvent the wheel in the process but I figured I'd ask first.

>

> I plan on converting my stack to LiveCode at some point. Info on how it's done in LC would be helpful as well. I looked at the forums and the dictionary but my eyes started to glaze over... Too much information.

>

>

> Terry Bowman, KA4HJH

> "The Mac Doctor"

>

>

>

>

[HC] Date and Time calculations

(Msg 3 of 5)

beckiergb <beckiergb@[redacted].com>

Friday, 16-Feb-2018 00:03 GMT

function timediff a, b

convert a to seconds

convert b to seconds

put abs(a-b) into diff

put diff mod 60 into s

if length(s) < 2 then put 0 before s

put diff div 60 into diff

put diff mod 60 into m

if length(m) < 2 then put 0 before m

put diff div 60 into h

return h & ":" & m & ":" & s

end timediff

put timediff("Feb 15, 2018 3:53:29 PM", "Nov 6, 2018 8:00:00 AM") -- yields

6328:06:31

convert a to seconds

convert b to seconds

put abs(a-b) into diff

put diff mod 60 into s

if length(s) < 2 then put 0 before s

put diff div 60 into diff

put diff mod 60 into m

if length(m) < 2 then put 0 before m

put diff div 60 into h

return h & ":" & m & ":" & s

end timediff

put timediff("Feb 15, 2018 3:53:29 PM", "Nov 6, 2018 8:00:00 AM") -- yields

6328:06:31

[HC] Date and Time calculations

(Msg 4 of 5)

ka4hjh <ka4hjh@[redacted].com>

Friday, 16-Feb-2018 00:09 GMT

> On Feb 15, 2018, at 7:03 PM, Rebecca Bettencourt beckiergb@[redacted].com[HyperCard] <HyperCard-Mailing-List> wrote:

>

> function timediff a, b

> convert a to seconds

> convert b to seconds

> put abs(a-b) into diff

> put diff mod 60 into s

> if length(s) < 2 then put 0 before s

> put diff div 60 into diff

> put diff mod 60 into m

> if length(m) < 2 then put 0 before m

> put diff div 60 into h

> return h & ":" & m & ":" & s

> end timediff

>

> put timediff("Feb 15, 2018 3:53:29 PM", "Nov 6, 2018 8:00:00 AM") -- yields 6328:06:31

I'll be taking a very close look at this tomorrow. Thanks.

>

> __,_._,

> ___

>

Terry Bowman, KA4HJH

"The Mac Doctor"

[HC] Date and Time calculations

(Msg 5 of 5)

ka4hjh <ka4hjh@[redacted].com>

Saturday, 17-Feb-2018 21:35 GMT

Thanks for all the help gang. I've got it working.

>

>

Terry Bowman, KA4HJH

"The Mac Doctor"

>

>

Terry Bowman, KA4HJH

"The Mac Doctor"

HyperCard® and HyperTalk™ remain trademarks of Apple, Inc.; other trademarked products and terms mentioned in this archive are the property of their respective trademark holders. Individual messages remain the intellectual property of their respective authors.