# Discussions

View Only

## How to calculate the number of hours between four date/time fields, excluding weekends

• #### 1.  How to calculate the number of hours between four date/time fields, excluding weekends

Posted 03-10-2023 05:35

let (
start = ToDate([Start Date]),
end = ToDate([End Date]),
onHoldStart = ToDate([On Hold Start Date]),
onHoldEnd = ToDate([On Hold Stop Date]),
duration = If(
Not(IsNull(start)) and Not(IsNull(end)) and Not(IsNull(onHoldStart)) and Not(IsNull(onHoldEnd)),
WeekdaySub(end, start) - WeekdaySub(onHoldEnd, onHoldStart),
0
),
durationInDays = ToDays(duration),
durationInHours = ToInt(Duration(0, 0, durationInDays).ToHours()),
durationInMinutes = ToInt(Duration(0, 0, durationInDays).ToMinutes())
);

durationInHours & " hours " & durationInMinutes & " minutes"

I'm getting error please see attached screenshot

Note: output field type is duration

------------------------------
manohar vankireddy
------------------------------

• #### 2.  RE: How to calculate the number of hours between four date/time fields, excluding weekends

Posted 03-10-2023 19:19

You're using javascript syntax which isn't allowed.

------------------------------
Jeff Peterson
------------------------------

• #### 3.  RE: How to calculate the number of hours between four date/time fields, excluding weekends

Posted 03-13-2023 04:30

Hi Jeff,