0

So i have 2 input fields(BeginTime and EndTime) and a user can insert time with a time picker plugin called Datebox using the 24 Hour time Format.
On Change those inputs should calculate the hours between those times.

e.g
BeginTime: 08:00
EndTime:16:00
Result: 8 Hours

Times like
BeginTime:18:00
EndTime:02:00
Result: 8 Hours
Should also be possible same goes with negative Hours
Now i only can manage to get the hours between Positive times and only with begintime > endtime here is my code:

var timehour = end.split('.')[0] - begin.split('.')[0];
var timeminut = end.split('.')[1] - begin.split('.')[1];

        if (timeminut< 0){
            timehour--;
            timeminut= 60 + timeminut;
        }...giving out the result  

So how do i calculate the other time possibilities?
P.S i am using jquery mobile

TheWandererr
  • 514
  • 1
  • 8
  • 34
  • Something like this: http://codepen.io/ezanker/pen/qNzZAb. How do you know when to get negative hours versus moving end time to next day? – ezanker Aug 26 '16 at 12:51
  • Hey, yea something like that. Well lets say i work in shifts from like 06:00 - 14:00 and 14:00 - 22:00 and 22:00 - 06:00. I would probably create 3 variables(boolean) and check which is active and then set the appropriate calculation option something like that. – TheWandererr Aug 26 '16 at 13:19
  • Where do negative hours come in? – ezanker Aug 26 '16 at 13:42
  • just if the beginn time is greater than the end time but it looks like it is already working – TheWandererr Aug 26 '16 at 13:44

0 Answers0