How to check whether current time is between time X and time Y?

Hey all,

For the past two days I have been trying to figure out how to set up a workflow that sets a store’s ifOpen to yes/no based on whether the user’s Current time is later than the store’s opening hour and earlier than the store’s closing hour.

I tried several methods but none worked. Searched the forum for answers but none specifically solves my case. I tried using <-range-> now and created what I believe to be an overly complicated workflow for something that in my head should be relatively simple (which doesn’t do the trick anyway).

Probably worth noting that the workflow is triggered by an API call in the backend and that I’ve used this ([Tips] Let Users setup their daily availabilities) as the base of my listed stores’ opening hours.

This is my current workflow:

First I’m updating the current store’s availabilities’ opening hours and closing hours to match the current date.

Then I’m setting the ifOpen to ‘yes’ based on the condition whether the current time is in the opening hour and closing hour range.

Finally, if the second action’s condition is false, I’m doing the opposite and set the ifOpen to ‘no’.

I know that I’m doing something (probably a lot) wrong here so is there anyone that has experience setting up something similar? Here’s a read-only if you want to take a closer look.

Thanks!

UPDATE:

I tried simplifying my workflow by adding a number variety of the Availabilities’ closing- and opening hours. Then I set up a workflow that checks whether the current time’s number (hours*60 + minutes) is greater than the opening hours number variety and smaller than the closing hours number variety.

Unfortunately that didn’t work either but I think this should be a little more in the right direction at least.

You must be close, is it possible to do the steps below:

Scenario:

  1. The store opens at 0800 hours = 8 * 60 = 480.
  2. The store closes at 1700 hours = 17*60 = 1020.

Workflow:

  1. Make the workflow check wether (current date/time:extract hours * 60 + current date/time: extract minutes) is >= step 1 AND < step 2. Based on this set IfOpen = YES
  2. Make the workflow check wether (current date/time:extract hours * 60 + current date/time: extract minutes) is < step 1 OR >= step 2. Based on this set IfOpen = NO

Scenario and Result:

  1. If you run the workflow at 1442 then step 3 will apply because 1442 hours = 14*60 + 42 = 882. 882 is >= 480 and < 1020 so the result should be IfOpen = YES.
  2. If you run the workflow at 1701 hours step 4 will apply because 1701 hours = 17*60 + 1 = 1021. 1021 is not < 480 but is >= 1020 so the result will be ifOpen = NO.

Of course you can replace current date/time with the date/time you want to check. Also assuming you can save the open en closing hours as hours+minutes in you DB.

Thanks for your reply @gerbertdelangen! I read it a couple of times and it seems to me that I’m already doing exactly what you’re saying here; what am I not seeing?

No problem, it’s an interesting problem. I updated it a couple of times (see the bold AND and OR). I tried this solution in the frontend with a couple of texts and conditions and it seemed to work. I don’t mind to have a look together through Skype since I need a similair function to set a maintenance window for another app btw, let me know.

Thanks, fixed those things but it still doesn’t work on my side. I have thouroughly checked for errors and any mistakes on my side but I believe everything is set up correctly. The API call sends out data successfully as well so the issue must be on Bubble side. I could do a Skype call - DM me details and a time and we’ll talk it through!

UPDATE:

Thanks @gerbertdelangen for the help! I looked into it further and the logic all seems to work except for the condition of current time < closing time. When I remove this part it works - the store’s ifOpen is set to yes. When I add a closing time it somehow doesn’t work. I tested if the formulas (current time’s h*60+m as well as closing time) returned the correct numbers and didn’t find any issues there.

Tomorrow I will try to set closing time to anywhere below the number 1000 to see if that changes anything.

Any thoughts on this, anyone?

You’re welcome. it seems you know design well so I’ll definitely reach out to you somewhere in the future :smile: .

As a temporary solution is it possible to use two boolean fields in order to determinewether the store is open? Maybe it will work.

  1. IfOpen_Open, use current date/time:extract hours * 60 + current date/time: extract minutes >= the time the store opens, set to True.
  2. ifOpen_Close, use current date/time:extract hours * 60 + current date/time: extract minutes < the time the store closes set to True.

If both booleans evaluate to True the store is open.

Reach out any day @gerbertdelangen!

Thanks for the alternative - tried that just now, didn’t work either. Something about the second part of the conditional is off and I can’t figure out what it is. The math adds up, the numbers add up. There’s literally nothing else I can think of that might be causing this not to work.

I’ll submit a ticket and see what they say. Thanks again!

1 Like

Any update?