0

Am trying to get number of hours between two time objects. Am using 24h time format. If the difference in hours is higler than 24 hours, I want to increase price for some cars.

User can select start time and end time from input typte=time: 10:25 / 23:45

Which is the best approach to do this. I google but that examples i dont understand clearly...

Ivan
  • 5,139
  • 11
  • 53
  • 86
  • Are the times in same day? Is that the assumption? – sabithpocker Mar 08 '16 at 14:59
  • [This answer](http://stackoverflow.com/a/1968175/2069813) might help you. – vcanales Mar 08 '16 at 15:00
  • @sabithpocker No rules can be on the same day, also may not be in the same day. I just want to get number of hours between two dates – Ivan Mar 08 '16 at 15:04
  • There is basically nothing as time object in javascript. There is only Date object, for which the answer in the above comment can be used. But for that you will need the date part as well, not just time. Or assume both times are in same date. – sabithpocker Mar 08 '16 at 15:12

2 Answers2

0

Just subtract them if they are date objects, if they are not make them.

Mihai Farcas
  • 119
  • 1
  • 7
0

You can get the amount of hours between two dates with:

var date1 = new Date('2016,03,10');
var date2 = new Date();

var hoursBetween = ((date1-date2)/1000)/3600;
vcanales
  • 1,818
  • 16
  • 20