[Solved] Adding time from a DB to user input time

Here’s a method that adds the hours together, adds the minutes together, and then displays them separated by a colon:

Note that it doesn’t convert minutes so if you, for example, add 45 minutes to 45 minutes, you’ll get ___:90.

In terms of explanation, it’s taking the text string such as “23:15” and making it into a list by breaking up the string using the “:” as a delimiter. So in that case, the resulting list contains {“23”,“15”}. I then reference the #1 item of the list which is “23” and add it to the #2 item of the list which is “15” to get 38.

You can see it in action in the same demo project (find the screen with your name). Note that it’s just pulling the time values from the two labels at the bottom of the screen… it’s not connected to the other coding I did for you before on that screen.

2 Likes

Just a note
The two circled components are not the same
image
They are actually two different variables.

1 Like

Why are they not the same? Don’t they reference the same value?

If I do this:

The label shows “goodbye” which means that the two variables are the same, right?

Or this one, the label shows “hello”:

1 Like

From experience, it fails intermittently and sometimes you get a result in the Test Web and a different one in Thunkable Live.

This is why I stayed away from them as they look the same but for some reason the value is not consistent with every update.

Good that it is giving the same result now.

1 Like

How about this? I separate the user’s time input fields into two lists called “report hr list” and “report min list”. "LattHour text is converted to minutes (* by 60). Assuming the user inputs the hour, then the minute, the “report min list” triggers the next block that sets app variable “lattminutes” by adding the new values in “LattHour” and “LattMin”. To convert back to hours, I divide by 60 and get hours and fraction. Using the decimal as a delimiter, i multiply the number after the decimal by 60 to convert back to minutes and join them. That’s the concept. After testing, what happens is that if I enter 1 hour and 5 minutes, the result is 1.499999999. It is doing the math correctly, but it is returning a number delimited by a decimal where I want a colon, and it is not rounding .4999999 to 5, and it is not placing the leading zero in front of the 5 (as written in the “report min list” to make it look like 1:05.

Thx for your inputs - appreciate it

Looks like a good plan. I don’t understand why you’re multiplying the decimal value by 6 though. If you had 66 minutes and you divide by 60 to get 1.1 hours, then you’d multiply the 0.1 hours by 60 to get 6 minutes.

It’s fine to use the list blocks for separating out decimal values as long as you keep in mind that you’re working with text strings so you don’t technically have numbers until you use a math operation (e.g. +, -, x, ÷) on them.

Often, the math blocks themselves will do what you need in a simpler way. For example, you can use the remainder block to divide 66 by 60 and get 6 as the number of minutes.

One way is not “better” than the other. It just depends what makes sense to you as a programmer.

1 Like

You caught me. Just corrected the 6 and 60. And edited the previous post with new blocks

1 Like

I am trying to take a number like 3.14159265 and set the decimal point as the delimiter. I can split the number into a 3 and the infinitely large number 14159265… I want the second number to be 14, just the first two digits in the number. How can this be done?

are you just interested in printing pi to 2 decimal places? use this:
image

if you want to split the parts, use this:

Or you can try substrings too, with from letter # being first occurrence index of decimal.

(reference docs are hyperlinked)

2 Likes

I think it’s best to add this kind of question to the topic you’ve already contributed to since it has details about the what/why/how of this issue and provides context.

Perhaps @jared can merge it with this topic?

1 Like

I’ve been working on that for 6 hours. You did it in 2 seconds

2 Likes

Glad it worked out for you - Happy Thunking! :v:

2 Likes

Sorry - I thought it was discreet enough a problem, but you are right. Def part of my original issue.

Not a big deal! Just figured it helps people to know the backstory instead of having to ask you the same questions again. Glad you’re making progress on this.

1 Like

Done! Thanks all!

#teamworkmakesthedreamwork

2 Likes

Down to the last hurdle. Shown is the DB from which a user selects an “FDP Start” time window using a list. If the user reports to work at 0500 local time, then row 3 is selected and the program runs properly. The problem is that if the user lives in SFO, the program needs to enter the row corresponding to the user’s body-clock time, not their local time. There are app user inputs for body clock and local time, so I have the information, but I’m not sure how to modify the input to the DB so that it references the correct row. Attached is the DB I made to come up with a correction to the input time, but I can’t figure out how to work that into a solution.


When you have a row id and you use the green index block (or a variable if that’s the case) for the row number, just use a math block to add the amount in the Base Time Zone table to it.

I think you mean something like this:


The top database is “FAR 117 FDP.” The bottom one is “FDP Correction.” If I do this, I think it simply changes the row ID by the correction amount. That doesn’t work since the FDP Start columns aren’t in equal increments. Eg is the FDP time is 1900, and the correction is -1, then the new time is 1800 which is still in row 8, so no correction. I believe you are telling me to correct from row 8 to row 7, but that wouldn’t yield the proper result.

But, if I change the database to increment by 1 hour, that will work. I’ll try it.