Time Calculation Help

Hello everyone,

Looking for a bit of help with time calculations. I’m using the API connector to get live train times which returns scheduled arrival and actual arrival time at a specified station as text.

I’m trying to display the delay time in minutes by calculating the difference between the two values. So far I have got a dynamic text box with (Actual Arrival:converted to number - Scheduled Arrival:converted to number)

This works fine if the actual and scheduled are within the same hour, however, if for example the actual arrival is 1710 and scheduled is 1650, the result is 60 obviously as it thinks we’re working with numbers rather than time.

Is there a way to convert the text to a time value so the calculation is correct? Or am I over complicating it?

Many thanks!

What format does the API provide the Arrival times?

Just as text

Wow, that’s a frustrating format from an API. Here’s how you could do it:

current date/time :change hours to {Actual Arrival :truncated to 2 :converted to number} change minutes to {Actual Arrival :truncated from end to 2 :converted to number} - current date/time :change hours to {Scheduled Arrival :truncated to 2 :converted to number} change minutes to {Scheduled Arrival :truncated from end to 2 :converted to number}

1 Like

In that case you’ll need to separate it into the hours and minutes.

I don’t know how the API response deals with times before 10am - i.e. is 8:15 represented as 815 or 0815?

If the latter you can just truncate to 2 to get the hours and truncate from end (2) to get the minutes.

Set a Date value to any arbitrary Date (it can be current date/time) and change the hours and minutes accordingly.

Then you can simply create a date object based on those values and subtract one from the other to get the time difference in minutes.

(this won’t work if the 2 times cross midnight though - so you’ll have to figure out how to account for that)

Here’s a simple example: Times From Text (bubbleapps.io)

Thanks both for your replies, I’ve given this one a go, I get as far as the second current date/time and it won’t let me do change hours. Apologies if I’m doing something wrong, I’m very much a beginner to this.

You are one click away from it working. Just click the “Formatted as minutes” and you’ll get the difference between the time you generated with truncating stuff and the current time.

You need to either turn on Parenthesis or the new Beta Expression builder.

:point_up: yup

This has worked a treat, thank you all very much for your help!

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.