Calculate Time Duration

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.

1 Like

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?

1 Like

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

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.

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

Hi there,

You can view a project here 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)

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).


Thanks @jane

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.

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

1 Like