Find the difference (in hours), between 2 dates

Hi All,
I have previously used WIX to build great websites but am progressing to the point that I need to begin using WIX code.

My first project is to build a form and backend database to capture user input. Is there a way that employees can fill in start and end dates in the form and then the length of time (in hours) between those two dates can be automatically calculated?

The DB is straight forward to setup but writing code for this calculation remains a mystery to me. I have taken a look at a number of examples and explanations but am at a loss.
Any help and pointers would be greatly appreciated. Thanks in advance.

Quin

Here’s a code snippet that should help:

let startDate = new Date(“2018-12-03T00:00:00Z”);
var now = new Date();
var startTimeStamp = (startDate).getTime();
var nowTimeStamp = now.getTime();
var microSecondsDiff = Math.abs(startTimeStamp - nowTimeStamp);
console.log("msecs diff: " + microSecondsDiff);
// Number of milliseconds in a day:
// 24 hrs/day * 60 minutes/hour * 60 seconds/minute * 1000 msecs/second
var daysDiff = Math.floor(microSecondsDiff / (1000 * 60 * 60 * 24));
console.log("days diff: " + daysDiff);
var minsDiff = Math.floor(microSecondsDiff / (1000 * 60));
console.log("minutes diff: " + minsDiff);

Many thanks Yisrael! I will try it out and get back to you.

Helped me very much, works great. You would laugh how long it was taking me
to solve this and so much more code. Thank you

This thread is old and will be closed. If you have other questions/issues feel free to open up a new thread.