# Conditional Statement to Trigger Open/Close for Store Hours

Hi, I have a list of stores that have open/close times for each day of the week. Based off what the store hours are, I’ve created conditional statements for a text that will say ‘Open’ if the user’s current time is within the store’s open to close time. The opposite will happen if the user’s current time is outside of the open to close time.

The conditional statement I’ve set keep saying a store is ‘Closed’ even though the store should be ‘Open’, based on the user’s time.

Here’s what the conditions are for the text (first 3 are open/close conditions that I need help on, last 2 are work as they should):

This is the backend vs front-end of the store’s hour table:

As you can see, the user’s time is 5:21pm but the text shows ‘Closed’.

Really appreciate any help given, thanks!

The problem to work with “Current date/time” is that you are using the DATE as well.

How you stored the open and close hours in your database? Could you share?

@rpetribu Ah that makes so much sense! Is there a way to just include dates or is that through a plugin?

Here’s the data type for hours:

Hi!

Try to store the open and close hours as number (in minutes) in your database.

Sumday 08:00 to 20:00 will be Sunday 480 to 1200.

08:00 = 8 x 60 = 480
20:00 = 20 x 60 = 1200

Now, just check the weekday of your user, using Current Date/Time, find this entry in your database and divide the Current Time by 60. If the result is between 480 and 1200, then your store is open!

Make sense?

1 Like

@rpetribu I get the logic behind this but I can’t seem to figure out ways to execute this in Bubble.

I’m facing three issues:
1. I inputted hours to be 480 to 1260, and when I divided these values by 60, I’m still seeing 480 and 1260 on the front-end side. How do I correctly create the formula to show 8:00am and 9:00pm?

Back-end:

Front-end:

2. How do I create another formula to divide the user’s current time by 60? (I do not see the division sign available)

3. If I’m still taking in user’s Current date and time, how does the date not mess up this new workflow and accidentally mark a store as closed?

Hi @sydneyng !

What I would do is:

1. Create a database to store the data of each Store (think you already did it). In this database, I would have 4 fields to control this “time” thing.
• Open_hour_text: 08:00
• Open_hour_number: 480
• Close_hour_text: 20:00
• Close_hour_number: 1200
1. In my Store’s page, in the text filed that displays the opening and closing hours, I would simply get the “Open_hou_text” and “Close_houre_text”. Simple as that…

2. Now, to dynamically toggle the sign “Open/Close” based in users Current Date/Time you will need extrat the hours and the minutes:

`Current Date/Time:Extrat Hours*60 + Current Date/Time:Extrat Minutes`

It the time is 14:40, then the result of this operation will be: 880, follow?
If 880 is between Open_hour_number and Close_hour_number , than your store is open.

Now, do a “Search for” to see if you get any result from you database with this constrains:

• Store = Current Page Store
• Weekday = Current Date/Time Weekday
• Open_hour_number < Current Date/Time:Extrat Hours*60 + Current Date/Time:Extrat Minutes
• Close_hour_number > Current Date/Time:Extrat Hours*60 + Current Date/Time:Extrat Minutes

If the :count of this Search is > 0, than your store is open.

3 Likes

@rpetribu followed your steps and it worked! Thanks so much

1 Like

Would this method work if the hours were like this:

Saturday: 5pm - 2am

if the time were 7pm, the open hour number would be less than the extracted hours + extracted minutes, but the closing hour would also be less than the extracted values, so the search would return empty.