# Calculate working hours

**URL:** <https://community.glideapps.com/t/calculate-working-hours/77505>\
**Category:** Ask for Help\
**Created:** [October 31, 2024, 11:32am UTC](https://community.glideapps.com/t/calculate-working-hours/77505 "2024-10-31T11:32:39Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![agung\_taufik1](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/agung_taufik1/32/80541_2.png) [@agung\_taufik1](https://community.glideapps.com/u/agung_taufik1)\
**Post date:** [October 31, 2024, 11:32am UTC](https://community.glideapps.com/t/calculate-working-hours/77505/1 "2024-10-31T11:32:39Z")

</div>

Hi, I want to calculate working hours duration by subtracting the office departure time from the office arrival time. However, the result doesn’t seem accurate when referring to hourly calculations. For example, if I clock in at 8:15 and clock out at 16:00, the result is 7.85 hours.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/2/4/24aefe836bac64857cf75307cb01c6cacefa0174.png)

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [October 31, 2024, 12:04pm UTC](https://community.glideapps.com/t/calculate-working-hours/77505/2 "2024-10-31T12:04:44Z")

</div>

It’s accurate based in the numbers you are using.  
`16-8.15=7.85`

You are calculating math using decimal numbers. You are not using date/time numbers. If you used date/time columns to calculate time difference, then it would be accurate. Or your decimal based times should be 100 based instead of 60 based, so 8,15 would actually be 8,25.

---

<div class="post-metadata">

**Author:** ![Jakub\_Molak](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jakub_molak/32/81347_2.png) [@Jakub\_Molak](https://community.glideapps.com/u/Jakub_Molak)\
**Post date:** [October 31, 2024, 12:21pm UTC](https://community.glideapps.com/t/calculate-working-hours/77505/3 "2024-10-31T12:21:52Z")

</div>

Hey there here is some Javascript that should work out the difference between the two times even though they are in a decimal format. This returns the difference in hours,minutes like the initial number. You just have to change p1 to the initial time and p2 to the end time. Only issue if the difference in minutes are exactly 0 it will return 0 and not 00

```auto
function parseTime(timeStr) {
    // Split hours and minutes, then use parseInt to convert safely, with defaults of 0
    const [hoursStr, minutesStr] = timeStr.split(',');
    const hours = parseInt(hoursStr, 10) || 0;
    const minutes = parseInt(minutesStr, 10) || 0;
    const date = new Date();
    date.setHours(hours, minutes, 0, 0); // Set hours, minutes, seconds, and milliseconds
    return date;
}

  
const time1 = parseTime(p1.toString());
const time2 = parseTime(p2.toString());

// Calculate the difference in milliseconds
const diffMs = time2 - time1;

// Convert milliseconds to total minutes
const diffMinutes = diffMs / (1000 * 60);

// Convert minutes to hours and minutes
const hours = Math.floor(diffMinutes / 60);
const minutes = Math.floor(diffMinutes % 60);

return hours + "," + minutes

```

---

<div class="post-metadata">

**Author:** ![agung\_taufik1](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/agung_taufik1/32/80541_2.png) [@agung\_taufik1](https://community.glideapps.com/u/agung_taufik1)\
**Post date:** [October 31, 2024, 12:51pm UTC](https://community.glideapps.com/t/calculate-working-hours/77505/4 "2024-10-31T12:51:53Z")

</div>

“Please help. Essentially, I have clock-in and clock-out times, and I want to round these times. For example, if the clock-in time is 08:09, it will be rounded to 08:10 (the rounded time). I use an IF validation: if the clock-in time is before 08:00, it will record as 08:00; if it’s after 08:00, it will record the rounded time, which is 08:10. I will use this result to calculate the hourly wage.”

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [October 31, 2024, 1:26pm UTC](https://community.glideapps.com/t/calculate-working-hours/77505/5 "2024-10-31T13:26:06Z")

</div>

How are you ending up with times in decimal form?

---

<div class="post-metadata">

**Author:** ![agung\_taufik1](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/agung_taufik1/32/80541_2.png) [@agung\_taufik1](https://community.glideapps.com/u/agung_taufik1)\
**Post date:** [October 31, 2024, 1:31pm UTC](https://community.glideapps.com/t/calculate-working-hours/77505/6 "2024-10-31T13:31:12Z")

</div>

I use format date

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/e/b/eb579d653ca0263652c3f908cd6249ba099831a7.png)

---

<div class="post-metadata">

**Author:** ![agung\_taufik1](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/agung_taufik1/32/80541_2.png) [@agung\_taufik1](https://community.glideapps.com/u/agung_taufik1)\
**Post date:** [October 31, 2024, 2:39pm UTC](https://community.glideapps.com/t/calculate-working-hours/77505/7 "2024-10-31T14:39:01Z")

</div>

"Okay, I have found a way to get the time in hours, but another issue has come up. When I try to add the result of the multiplication, the result isn’t as expected. If I multiply the durasi jam with the gaji perjam, the result is incorrect. How can I accurately calculate the jam result so the calculation is correct?

Note:

- Entry time is (kolom Rounded jam masuk)
- Exit time is (kolom rounded jam pulang)
- Subtraction of exit time minus entry time = (kolom durasi jam untuk perhitungan gaji)
- Hourly wage is (kolom gaji perjam)
- Calculated hourly wage result is (kolom hitung gaji perjam)"

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/b/e/be3ed057ac55993f5ea0c531733a75fc5156cf51.png)

---

<div class="post-metadata">

**Author:** ![Jakub\_Molak](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jakub_molak/32/81347_2.png) [@Jakub\_Molak](https://community.glideapps.com/u/Jakub_Molak)\
**Post date:** [October 31, 2024, 5:01pm UTC](https://community.glideapps.com/t/calculate-working-hours/77505/8 "2024-10-31T17:01:12Z")

</div>

You would need to convert the minutes of time difference to a % so 1 hour 30 minutes would be 1.5 as 30 is 50% of 60 when multiplied together with your hourly wage this should provide the correct value

---

<div class="post-metadata">

**Author:** ![agung\_taufik1](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/agung_taufik1/32/80541_2.png) [@agung\_taufik1](https://community.glideapps.com/u/agung_taufik1)\
**Post date:** [October 31, 2024, 5:08pm UTC](https://community.glideapps.com/t/calculate-working-hours/77505/9 "2024-10-31T17:08:33Z")

</div>

“Sorry, I didn’t quite understand how to convert minutes to a percentage. If you don’t mind, could you show a screenshot?”

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [November 1, 2024, 12:02am UTC](https://community.glideapps.com/t/calculate-working-hours/77505/10 "2024-11-01T00:02:56Z")

</div>

So if I clockout at 08:16, does it round to 08:20 or 08:10?

---

<div class="post-metadata">

**Author:** ![agung\_taufik1](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/agung_taufik1/32/80541_2.png) [@agung\_taufik1](https://community.glideapps.com/u/agung_taufik1)\
**Post date:** [November 1, 2024, 1:34am UTC](https://community.glideapps.com/t/calculate-working-hours/77505/11 "2024-11-01T01:34:05Z")

</div>

08:10

---

<div class="post-metadata">

**Author:** ![Jakub\_Molak](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jakub_molak/32/81347_2.png) [@Jakub\_Molak](https://community.glideapps.com/u/Jakub_Molak)\
**Post date:** [November 1, 2024, 9:10am UTC](https://community.glideapps.com/t/calculate-working-hours/77505/12 "2024-11-01T09:10:33Z")

</div>

For example. If the entry time was 8:15 and exit was 16:00 the difference would be 7 hour 45 minutes however to use this time with your hourly wage you need to convert it minutes/60 in this case 45/60 = 0.75 so the number you would multiple with your hourly wage would be 7.75 instead of 7:45.  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/optimized/3X/9/a/9a6596ca41dadb81d89adce8bf355bc03574f27d_2_690x35.png)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/c/8/c8cc9026436ca167c67ba94312ad846051a20e29.png)  
As shown above using that formula you should be able to convert your time into a decimal number which can be used to workout the final wage
