I want users to input a duration into my database.
I need to sort things by duration so I will need to calculate the total seconds and sort by that.
How do I calculate
Hours x 3600 + Minutes x 60 + Seconds
… and store this in my database?
I want users to input a duration into my database.
I need to sort things by duration so I will need to calculate the total seconds and sort by that.
How do I calculate
Hours x 3600 + Minutes x 60 + Seconds
… and store this in my database?
Hi there, @flyhigh… there is certainly more than one way to go about this one, but I would probably use custom states to do the hours and minutes conversions and then add those conversions together along with the seconds in a workflow step.
So, you could add two custom states to your page… let’s call them hours converted
and minutes converted
, and they are both numbers. Then, you add workflow steps so that when the hours and minutes dropdowns shown in your screenshot are changed, the associated custom states are updated by multiplying the inputs by 3600 and 60. Finally, when you submit the result, you have a workflow step that updates a field, let’s call it total seconds
, to be hours converted
plus minutes converted
plus seconds
.
Make sense? If some screenshots would help you get it set up, just let me know and I can grab some. Hope this helps.
Best…
Mike
Hey, @mikeloc, thanks for your reply. I am new to Bubble.io and never heard of custom states before. Looks like a handy tool I will use often… I watched a tutorial and I think I understood it.
May you give me a hint where/how I can do the calculations?
Sure thing, @flyhigh… happy to provide more details.
For the purposes of my example, I am working right on the index page, and I have added a field called total seconds
to the User
data type. Then, I added two custom states on the index page itself…
Next, I added workflow steps to update those custom states with a calculated number when the hours and minutes inputs on the page or changed (I’m only showing the hours calculation below, but the one for minutes is done the same way)…
Finally, I created a workflow for a button called Submit Result that adds the numbers in the custom states to the number of seconds…
So, that’s what I’ve got… hope these details are helpful.
Best…
Mike