0

I need to calculate work hours between two Date. I set up two date.

    var startDate = new Date("2/25/2017 20:30");
    var endDate = new Date ("3/28/2017 20:58");

I set up days like objects in which i have work start and work end.

var monday = {"start":"09:00", "end":"17:00"};
var tuesday = {"start":"09:00", "end":"17:00"};
var wednesday = {"start":"09:00", "end":"17:00"};
var thursday = {"start":"09:00", "end":"17:00"};
var friday = {"start":"08:00", "end":"13:00"};
var saturday = {"start":"08:00", "end":"11:00"};
var sunday = {"start":"08:00", "end":"09:00"};

Then i put all objects in array:

 var workDays = [monday, tuesday, wednesday, thursday, friday, saturday, sunday];

I don't know how to subtract hours in each day. For example, in monday: 17:00 - 09:00 = 8 hours.

I tried this:

var mondayStart = monday.start;
var mondayEnd= monday.end;

In console i get right start and end time of monday object, but i have problem with subtraction.

var mondayDifference = mondayEnd - mondayStart;

console.log(mondayDifference);

But, in console i get: NaN (not a number).

I'll be thankfull for any hints or help.

lukpar
  • 27
  • 5
  • Possible duplicate of [How to get the hours difference between two date objects?](http://stackoverflow.com/questions/19225414/how-to-get-the-hours-difference-between-two-date-objects) – Drew Kennedy Feb 25 '17 at 21:55

1 Answers1

1

If you are given the real case not only POC, parseInt will be enough to get the difference

var mondayDifference = parseInt(monday.end) - parseInt(monday.start);
                       // "17:00" will be 17     ..so on
Abdennour TOUMI
  • 87,526
  • 38
  • 249
  • 254