Hi Sheena,

yes that's possible. Calculating with dates can be a bit tricky. You have to put in your timezone instead of mine ("Europe/Berlin") and if your time is UTC - x hrs, you have to change "add" to "subtract".

Here's an example for 2 calculation fields. The calculations consider every possibility: Start and End outside time range (regardless of start/end before 7:30 or after 4:30), one inside, one outside, both inside.

Field: hrs within range

``````var TC = parseFloat(moment(@YourStartField).tz("Europe/Berlin").format("ZZ"))/100;

var start = moment(@YourStartField).add(TC,"h")
var end = moment(@YourEndFeild).add(TC,"h");

var rangeStart = moment("07:30 AM","h:m a");
var rangeEnd =  moment("04:30 PM","h:m a");

var hrsStart =  start >= rangeStart && start <= rangeEnd ? rangeEnd.diff(start, "m")/60 : 0;

var hrsEnd = end >= rangeStart && end <= rangeEnd ? rangeEnd.diff(end, "m")/60 : 0;

hrsStart > hrsEnd ? hrsStart - hrsEnd : hrsEnd
``````

Field: hrs outside range

`````` var TC = parseFloat(moment(@YourStartField).tz("Europe/Berlin").format("ZZ"))/100;

var start = moment(@YourStartField).add(TC,"h")
var end = moment(@YourEndFeild).add(TC,"h");

var rangeStart = moment("7:30 am","h:m a");
var rangeEnd =  moment("4:30 pm","h:m a");

var hrsStart =  start < rangeStart ? rangeStart.diff(start, "m")/60 : start > rangeEnd ? start.diff(rangeEnd, "m")/60 : 0;

var hrsEnd = end < rangeStart ? rangeStart.diff(end, "m")/60 : end > rangeEnd ? end.diff(rangeEnd, "m")/60 : 0;

``````

Rainer
rg@delos-consulting.com

Answer for the deleted question of John:
Yes, that's possible.