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

**URL:** <https://community.thunkable.com/t/solved-adding-time-from-a-db-to-user-input-time/1657453>\
**Category:** Questions about Thunkable X\
**Tags:** solved, beginner\
**Created:** [December 20, 2021, 2:58am UTC](https://community.thunkable.com/t/solved-adding-time-from-a-db-to-user-input-time/1657453 "2021-12-20T02:58:57Z")\
**Posts on this page:** 20\
**Page:** 2

<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:** [December 27, 2021, 6:27am UTC](https://community.thunkable.com/t/solved-adding-time-from-a-db-to-user-input-time/1657453/22 "2021-12-27T06:27:45Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/e/b/eb148683c51a6d09b92fb958d702f023cccabf15.png)

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](https://x.thunkable.com/copy/a6f01aa3bb24259bd52d233bdde47da9) (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.

---

<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:** [December 27, 2021, 7:16am UTC](https://community.thunkable.com/t/solved-adding-time-from-a-db-to-user-input-time/1657453/23 "2021-12-27T07:16:12Z")

</div>

Just a note  
The two circled components are not the same  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/c/4/c443573c92d04b917e8bed7f50fab80ce72195bb.png)  
They are actually **two different variables**.

---

<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:** [December 27, 2021, 8:58am UTC](https://community.thunkable.com/t/solved-adding-time-from-a-db-to-user-input-time/1657453/24 "2021-12-27T08:58:34Z")

</div>

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

If I do this:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/d/8d72c57d9b463974fd338d3caae6cb828952b265.png)

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

Or this one, the label shows “hello”:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/7/974e5d7a393bc467381e49d9809b5281dfa67f57.png)

---

<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:** [December 27, 2021, 9:13am UTC](https://community.thunkable.com/t/solved-adding-time-from-a-db-to-user-input-time/1657453/25 "2021-12-27T09:13:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cohoes41a8gy](https://avatars.discourse-cdn.com/v4/letter/c/a5b964/32.png) [@cohoes41a8gy](https://community.thunkable.com/u/cohoes41a8gy)\
**Post date:** [December 27, 2021, 2:09pm UTC](https://community.thunkable.com/t/solved-adding-time-from-a-db-to-user-input-time/1657453/26 "2021-12-27T14:09:27Z")

</div>

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

 ![Screen Shot 2021-12-27 at 10.54.50 AM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/e/4/e4770944e46f70c602e5a5487e614fd9d6b9014d.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:** [December 27, 2021, 3:59pm UTC](https://community.thunkable.com/t/solved-adding-time-from-a-db-to-user-input-time/1657453/27 "2021-12-27T15:59:38Z")

</div>

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](https://docs.thunkable.com/math#get-remainder) 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.

---

<div class="post-metadata">

**Author:** ![cohoes41a8gy](https://avatars.discourse-cdn.com/v4/letter/c/a5b964/32.png) [@cohoes41a8gy](https://community.thunkable.com/u/cohoes41a8gy)\
**Post date:** [December 27, 2021, 4:00pm UTC](https://community.thunkable.com/t/solved-adding-time-from-a-db-to-user-input-time/1657453/28 "2021-12-27T16:00:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cohoes41a8gy](https://avatars.discourse-cdn.com/v4/letter/c/a5b964/32.png) [@cohoes41a8gy](https://community.thunkable.com/u/cohoes41a8gy)\
**Post date:** [December 28, 2021, 12:39am UTC](https://community.thunkable.com/t/solved-adding-time-from-a-db-to-user-input-time/1657453/29 "2021-12-28T00:39:33Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![manyone](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@manyone](https://community.thunkable.com/u/manyone)\
**Post date:** [December 28, 2021, 1:32am UTC](https://community.thunkable.com/t/solved-adding-time-from-a-db-to-user-input-time/1657453/30 "2021-12-28T01:32:29Z")

</div>

are you just interested in printing pi to 2 decimal places? use this:  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/1/4/142321a9d7e93ab1dd4d2ee93a3f151a19736d3f.png)

if you want to split the parts, use this:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/5/7/5701235133ef0bcd6d0bda7ef648964733f4433e.png)

---

<div class="post-metadata">

**Author:** ![kartik14](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/kartik14/32/44782_2.png) [@kartik14](https://community.thunkable.com/u/kartik14)\
**Post date:** [December 28, 2021, 2:21am UTC](https://community.thunkable.com/t/solved-adding-time-from-a-db-to-user-input-time/1657453/31 "2021-12-28T02:21:41Z")

</div>

Or you can try [substrings](https://docs.thunkable.com/text#get-substring) too, with `from letter #` being [first occurrence](https://docs.thunkable.com/text#find-first-last-occurrence) index of decimal.

(reference docs are hyperlinked)

---

<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:** [December 28, 2021, 2:49am UTC](https://community.thunkable.com/t/solved-adding-time-from-a-db-to-user-input-time/1657453/32 "2021-12-28T02:49:32Z")

</div>

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?

> [@\[Solved\] Adding time from a DB to user input time](https://community.thunkable.com/t/solved-adding-time-from-a-db-to-user-input-time/1657453/25):
>
> 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.

---

<div class="post-metadata">

**Author:** ![cohoes41a8gy](https://avatars.discourse-cdn.com/v4/letter/c/a5b964/32.png) [@cohoes41a8gy](https://community.thunkable.com/u/cohoes41a8gy)\
**Post date:** [December 28, 2021, 3:13am UTC](https://community.thunkable.com/t/solved-adding-time-from-a-db-to-user-input-time/1657453/33 "2021-12-28T03:13:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kartik14](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/kartik14/32/44782_2.png) [@kartik14](https://community.thunkable.com/u/kartik14)\
**Post date:** [December 28, 2021, 3:15am UTC](https://community.thunkable.com/t/solved-adding-time-from-a-db-to-user-input-time/1657453/34 "2021-12-28T03:15:20Z")

</div>

Glad it worked out for you - Happy Thunking! ✌

---

<div class="post-metadata">

**Author:** ![cohoes41a8gy](https://avatars.discourse-cdn.com/v4/letter/c/a5b964/32.png) [@cohoes41a8gy](https://community.thunkable.com/u/cohoes41a8gy)\
**Post date:** [December 28, 2021, 3:25am UTC](https://community.thunkable.com/t/solved-adding-time-from-a-db-to-user-input-time/1657453/35 "2021-12-28T03:25:57Z")

</div>

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

---

<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:** [December 28, 2021, 4:43am UTC](https://community.thunkable.com/t/solved-adding-time-from-a-db-to-user-input-time/1657453/36 "2021-12-28T04:43:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)\
**Post date:** [December 28, 2021, 4:48am UTC](https://community.thunkable.com/t/solved-adding-time-from-a-db-to-user-input-time/1657453/37 "2021-12-28T04:48:56Z")

</div>

Done! Thanks all!

#teamworkmakesthedreamwork

---

<div class="post-metadata">

**Author:** ![cohoes41a8gy](https://avatars.discourse-cdn.com/v4/letter/c/a5b964/32.png) [@cohoes41a8gy](https://community.thunkable.com/u/cohoes41a8gy)\
**Post date:** [December 28, 2021, 4:54pm UTC](https://community.thunkable.com/t/solved-adding-time-from-a-db-to-user-input-time/1657453/38 "2021-12-28T16:54:15Z")

</div>

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.

 ![Screen Shot 2021-12-28 at 11.34.15 AM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/e/c/ec48d32f08782999dc4ece08f574e9a395876af5.png)  
 ![Screen Shot 2021-12-28 at 11.46.19 AM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/d/9de3da3371dfd58ead16706929ed5469ad6166b0.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:** [December 28, 2021, 8:47pm UTC](https://community.thunkable.com/t/solved-adding-time-from-a-db-to-user-input-time/1657453/39 "2021-12-28T20:47:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cohoes41a8gy](https://avatars.discourse-cdn.com/v4/letter/c/a5b964/32.png) [@cohoes41a8gy](https://community.thunkable.com/u/cohoes41a8gy)\
**Post date:** [December 28, 2021, 9:32pm UTC](https://community.thunkable.com/t/solved-adding-time-from-a-db-to-user-input-time/1657453/40 "2021-12-28T21:32:39Z")

</div>

I think you mean something like this:

 ![Screen Shot 2021-12-28 at 4.26.31 PM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/4/e/4e11c75285cc8a2b8e64f51dee0bcea97bc91c9b.png)  
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.

---

<div class="post-metadata">

**Author:** ![cohoes41a8gy](https://avatars.discourse-cdn.com/v4/letter/c/a5b964/32.png) [@cohoes41a8gy](https://community.thunkable.com/u/cohoes41a8gy)\
**Post date:** [December 28, 2021, 9:46pm UTC](https://community.thunkable.com/t/solved-adding-time-from-a-db-to-user-input-time/1657453/41 "2021-12-28T21:46:49Z")

</div>

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

[Previous page](https://community.thunkable.com/t/solved-adding-time-from-a-db-to-user-input-time/1657453.md?page=1)

[Next page](https://community.thunkable.com/t/solved-adding-time-from-a-db-to-user-input-time/1657453.md?page=3)
