Calculating time between two times in hours and minutes

Hi all,

I have seen so many people asking for this and couldn’t really find an answer that helped me solve this, that I had to look outside of Adalo to solve it.

USE CASE: You have a start time and an end time and want to display HOURS and MINUTES between those two times.

When you subtract START TIME from END TIME in Adalo you get a decimal number where 1 equals 24 hours.

So let’s assume the following:

TOTAL TIME = END TIME - START TIME

Let’s assume that the difference between those was 0.582

So

TOTAL TIME = 0.582

To get the hours of this number you multiply it by 24 and remove the decimals.

TOTAL HOURS = TOTAL TIME * 24 - “any decimal to the right of the .”

0.582 * 24 = 13.968

Now you remove the decimals and you get 13 hours. That is what you want.

To achieve that in Adalo you do that by using the INT() function so:

TOTAL HOURS = INT(TOTAL TIME * 24)

TOTAL HOURS = INT(13.968)

TOTAL HOURS = 13

To get the minutes the process is similar but now you want to process the decimals to calculate the minutes.

You again calculate the TOTAL TIME and TOTAL HOURS, so you can then subtract the TOTAL HOURS from that number and keep only the decimals.

So you first convert the result to a 24 hour fraction and then subtract it from TOTAL TIME so you get only the decimals so you can calculate the minutes in fractional format.

TOTAL MINUTES = (((TOTAL TIME * 24) - “any decimal to the right of the .”) * 60) - “any decimal to the right of the .”

As before to get rid of decimals you use the INT() function

TOTAL MINUTES = INT(((TOTAL TIME * 24) - INT(total time * 24)) * 60)

TOTAL MINUTES = INT((13.968 - INT(13.968)) * 60)

TOTAL MINUTES = INT((13.968 - 13) * 60)

TOTAL MINUTES = INT(0.968 * 60)

TOTAL MINUTES = INT(58.08)

TOTAL MINUTES = 58

So now you calculated your total hours and total minutes you can display them!

TOTAL TIME = END TIME - START TIME

TOTAL TIME = 0.582 <------ as an example for the calculations

TOTAL HOURS = INT(TOTAL TIME * 24) = 13 hours

TOTAL MINUTES = INT(((TOTAL TIME * 24) - INT(TOTAL TIME * 24)) * 60) = 58 minutes

In Adalo I use two update function, one to first calculate TOTAL TIME and then another after that so that we can use the result of that calculation.

image

In the next action I calculate the TOTAL HOURS and TOTAL MINUTES

image

The catch is that for where minutes is less than 10 minutes it will not display a 0 to the left so I do two labels with visibility conditional to minutes < than 10 and then add a 0 to the left of TOTAL minutes in the label.

Happy calculations!

2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.