0

I have two dates in Javascript (a starting date, and an end date), and I want to get how much time passed between 2 hours within that time range. The hours are 23 (11pm) and 06 (6am).

So, if the starting date is

Oct, 15 - 20:00

And the end date is:

Oct, 19 - 04:15

The result would be

26 hs and 15 min

15/10 to 16/10 --> 23 - 6:00  :   7:00 hours
16/10 to 17/10 --> 23 - 6:00  :   7:00 hours
17/10 to 18/10 --> 23 - 6:00  :   7:00 hours
18/10 to 19/10 --> 23 - 4:15  :   5:15 hours
--------------------------------------------
                                 26:15 hours

I hope it's clear!

nick
  • 2,819
  • 5
  • 33
  • 69
  • Take a look for detailed discussion https://stackoverflow.com/questions/3224834/get-difference-between-2-dates-in-javascript – ShivCK May 12 '19 at 15:35
  • That's not my question – nick May 12 '19 at 15:35
  • I got your question. Will date format remain like this `Oct, 15 - 20:00` always? – ShivCK May 12 '19 at 15:47
  • not necessary, I got the starting dates as Date objects – nick May 12 '19 at 15:47
  • 1
    Have you tried anything yet? – ADyson May 12 '19 at 16:03
  • 1
    Starting from the older date, adjust the hours to the start hour. Make a new date from that result and then set the hours (and whatever else) forward according to the interval. Take the minimum of that date and the end date of the overall range, subtract, and repeat until you exhaust the range. – Pointy May 12 '19 at 16:19

0 Answers0