Author Topic: Does anyone have code for performing time calculations?  (Read 2752 times)

0 Members and 1 Guest are viewing this topic.

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Does anyone have code for performing time calculations?
« 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?

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Does anyone have code for performing time calculations?
« Reply #1 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

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Does anyone have code for performing time calculations?
« Reply #2 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.
You're not done when it works, you're done when it's right.

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Re: Does anyone have code for performing time calculations?
« Reply #3 on: November 16, 2019, 08:56:47 am »
Fantastic! Thanks for the help.