QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: hanness on November 16, 2019, 01:00:25 am

Title: Does anyone have code for performing time calculations?
Post by: hanness on November 16, 2019, 01:00:25 am
As a simple example, say that you have 2 times:

Jan 1, 2019 11:00:00 PM
Jan 2, 2019  1:00:00 AM

This one is an obvious example where the time difference is 0 years, 0 months, 0 days, 2 hours, 0 minutes, 0 seconds. But that is basically what I am after: Code that calculates the time difference between any 2 sets of dates and time.

Anyone have code like that or reference to a formula that I can convert into QB64 code?
Title: Re: Does anyone have code for performing time calculations?
Post by: Petr on November 16, 2019, 03:42:43 am
Hi. This thread can be useful and interest for you.  I advise you to read it all in case you want to count down (or just count) time over several centuries. This thread  is also about the problem of leap years:   https://www.qb64.org/forum/index.php?topic=1637.0
Title: Re: Does anyone have code for performing time calculations?
Post by: STxAxTIC on November 16, 2019, 07:59:05 am
Prolly the best thing is convert each time to unix epoch (seconds since the beginning of 1970), do the subtraction, and then convert back to hour/day format.
Title: Re: Does anyone have code for performing time calculations?
Post by: hanness on November 16, 2019, 08:56:47 am
Fantastic! Thanks for the help.