# Calculate Time Duration

**URL:** <https://community.thunkable.com/t/calculate-time-duration/1361156>\
**Category:** Questions about Thunkable X\
**Created:** [June 24, 2021, 5:35am UTC](https://community.thunkable.com/t/calculate-time-duration/1361156 "2021-06-24T05:35:01Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![aikansh.dua044gefzj](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@aikansh.dua044gefzj](https://community.thunkable.com/u/aikansh.dua044gefzj)\
**Post date:** [June 24, 2021, 5:35am UTC](https://community.thunkable.com/t/calculate-time-duration/1361156/1 "2021-06-24T05:35:01Z")

</div>

Hi everyone I would like to know how can we calculate time duration between two times my aim is to find time difference and see if its greater then the user would get a message saying YOU ARE LATE BY \_\_ HOURS \_\_ MINUTES . I wasnt able to find any api but I tried a workaround which just subtracted The time set by me and the current if its less than 1 report 1 hour late else report you are on time However this was working fine until let’s say my time to calculate from is 9:30 so if the current time is 10:00 it should return 1 hour but it’s saying 1 hour late so can anyone show me how to calculate time difference these are my blocks.

 ![Screenshot 2021-06-24 110419](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/7/9/7974bca195db55b76017eaa5a7bc58949c5b6063.png)

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [June 24, 2021, 5:42am UTC](https://community.thunkable.com/t/calculate-time-duration/1361156/2 "2021-06-24T05:42:12Z")

</div>

What is the source of the two times you want to check? Are the times being selected, or typed in or determined by the device’s clock?

---

<div class="post-metadata">

**Author:** ![aikansh.dua044gefzj](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@aikansh.dua044gefzj](https://community.thunkable.com/u/aikansh.dua044gefzj)\
**Post date:** [June 24, 2021, 5:54am UTC](https://community.thunkable.com/t/calculate-time-duration/1361156/3 "2021-06-24T05:54:18Z")

</div>

Currently the time with which I want to check if he is late is is just in the blocks I.e 9:30 am and the other comparison time is the user’s current time. To simplify it is a attendance system which checks that if the user is late than the reaching time which is 9:30am warn him with a alert block saying if he is late by \_\_\_ hours \_\_ minutes

---

<div class="post-metadata">

**Author:** ![emma0122](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/emma0122/32/108510_2.png) [@emma0122](https://community.thunkable.com/u/emma0122)\
**Post date:** [June 24, 2021, 8:02am UTC](https://community.thunkable.com/t/calculate-time-duration/1361156/4 "2021-06-24T08:02:09Z")

</div>

It is hard to understand what you are saying it is sounding too confusing, Can you please present your problem in a more clear way.

---

<div class="post-metadata">

**Author:** ![aikansh.dua044gefzj](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@aikansh.dua044gefzj](https://community.thunkable.com/u/aikansh.dua044gefzj)\
**Post date:** [June 24, 2021, 8:31am UTC](https://community.thunkable.com/t/calculate-time-duration/1361156/5 "2021-06-24T08:31:18Z")

</div>

To simplify my statement I need to calculate duration between two given times one of which is the system current time

---

<div class="post-metadata">

**Author:** ![jane](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jane/32/27575_2.png) [@jane](https://community.thunkable.com/u/jane)\
**Post date:** [June 24, 2021, 9:46am UTC](https://community.thunkable.com/t/calculate-time-duration/1361156/6 "2021-06-24T09:46:44Z")

</div>

Hi there,

You can view a project [here](https://x.thunkable.com/projectPage/60d44d1394ea3200113c32eb/) that will calculate the difference between a given start time and the current time.

This project calculates the total minutes between the current time and the given start time.  
This is done by calculating `(difference in hours * 60) + (difference in minutes)`  
(Eg. if the event starts at 10.30 and it is currently 9.45, the total minutes = `(1 * 60) + (-15) = 45`)

 ![Screen Shot 2021-06-24 at 10.44.58 AM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/6/9/69b28c054e821df01a783f0cf8fd24a31fb64d97.png)

If this is total number of minutes is 0, it says that the event is starting right now.  
If this is greater than 0, it says that the event starts in X hours and Y minutes.  
If it is less than 0, it says that you are late! The event started X hours and Y minutes ago.  
(X = total minutes divided by 60, Y = remainder of total minutes divided by 60).

 ![Screen Shot 2021-06-24 at 10.45.28 AM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/e/c/ec3d9bfd9de9ca00541793cefbc48b3d7a9b43b1.png)

---

<div class="post-metadata">

**Author:** ![aikansh.dua044gefzj](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@aikansh.dua044gefzj](https://community.thunkable.com/u/aikansh.dua044gefzj)\
**Post date:** [June 24, 2021, 11:52am UTC](https://community.thunkable.com/t/calculate-time-duration/1361156/7 "2021-06-24T11:52:29Z")

</div>

Thanks @jane

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [June 24, 2021, 11:53am UTC](https://community.thunkable.com/t/calculate-time-duration/1361156/8 "2021-06-24T11:53:47Z")

</div>

I simply use a Google sheet having 3 columns  
start time  
end time  
result (sheet calculation of end time - start time)

In my code, I update start time and end time and read result. It always works and the code becomes simple.

---

<div class="post-metadata">

**Author:** ![aikansh.dua044gefzj](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@aikansh.dua044gefzj](https://community.thunkable.com/u/aikansh.dua044gefzj)\
**Post date:** [June 24, 2021, 11:55am UTC](https://community.thunkable.com/t/calculate-time-duration/1361156/9 "2021-06-24T11:55:19Z")

</div>

Thanks @muneer for another solution, It’s a good idea but I want this to be an offline feature

---

<div class="post-metadata">

**Author:** ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)\
**Post date:** [November 8, 2024, 1:20pm UTC](https://community.thunkable.com/t/calculate-time-duration/1361156/10 "2024-11-08T13:20:10Z")

</div>


