Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6578829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:49:17+00:00 2026-05-25T15:49:17+00:00

I had an idea to store hour-by-hour availability using a binary string that I

  • 0

I had an idea to store hour-by-hour availability using a binary string that I wanted to run by the community for advice.

My idea is generate a binary string that indicates availability for any given hour in the week using “0” for unavailable and “1” for available. I could then query against the binary column with the integer for the “current hour” with using the bitwise “and” operator. A string would look like the following

# Open sunday at 6:00am and close at 6:00pm (repeats 0 for remainder of hours)
000000111111111111000000...

Looking at the page at 4:00pm on Sunday would run the bitwise “and” with the previous string and this:

# Sunday at 4:00pm (repeats 0 for remainder of hours)
000000000000000100000000

If the returning bitwise comparison resulted in a value greater than 1, the record is currently available.

I have two questions. The first is which datatype I should store the value as. It’ll be 168 bit value at most (7 days * 24 hours). The second is which functions Postgres provides that would be able to accomplish what I mentioned. Something like this:

# String truncated for readability
WHERE some_column & $number_for_current_hour > 0

Thanks for reading! Any feedback is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:49:17+00:00Added an answer on May 25, 2026 at 3:49 pm

    You might just be better off if you store both an “Open Time” and a “Close Time”. This will be greatly easier for developers to process. If you have some sort of need for multiple open periods during the day, such as places that are open in the morning, closed at lunch, and then open again in the afternoon, I suggest that you create a table of “open times” with a “Open Time” and “Close Time” as well as foreign key linking back to the original table so that you can store multiple open periods. You may think you are being clever with your bitwise or stuff, but really just making things more complicated. Plus, you can’t accommodate for things happening on the half hour, or even finer resolution. Re-reading the question, I see you want to store multiple days. If you need different open times for each day, then my second solution would work well. Have a table like this.

    ID (INT), F_ID (INT), DAY_OF_WEEK (INT), OpenTime (Time), CloseTime (Time)

    ID is just auto increment for this table, F_ID is a foreign key back to the original table, day of week can be an integer or enum representing day of week, OpenTime and CloseTime are “Time” fields which can store a time, without the date. This should make things much more clear to yourself, and anybody else having to work on the code in the future. Plus it will probably be faster to do lookups, as you can index your time fields. Doing a binary xor is equivalent to using “LIKE ‘%word%’ for seaching strings and should be avoided.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had the idea of a search engine that would index web items like
I had an idea, if I add a python .py file to my C#
I had an idea for a client-side language other than JavaScript, and I'd like
I had an idea I was mulling over with some colleagues. None of us
I had this idea of creating a count down timer, like 01:02, on the
It seems like Microsoft had a great idea with the ObservableCollection. They are great
I was wondering if anyone had a better idea how to do this. atm
I'm trying to implement a data compression idea I've had, and since I'm imagining
I currently work for a social networking website. My boss recently had the idea
I had an idea about hashed passwords and salt values. Since I'm rather new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.