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 7739741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:35:51+00:00 2026-06-01T08:35:51+00:00

I have a scenario where I want to be able to SELECT rows from

  • 0

I have a scenario where I want to be able to SELECT rows from a MySQL table, but exclude rows where the current time-of-day is inside a time-range.

Example:
The “quiet” period for one row is 10pm – 8:30am.
My SQL SELECT statement should not return that row if the current server time is after 10pm or before 8:30am.

Example 2: The “quiet period” is NULL and ignored.

Example 3: A new row is created with a quiet period from 9:53am to 9:55am. If the current server time is in that 2-minute window, the row is not returned by the SELECT.

My question:
What data format would you use in the database, and how would you write the query?

I have thought about a few different approaches (defining start_time as one column and duration as another, defining both in seconds… or using Date stamps… or whatever). None of them seem ideal and require a lot of calculation.

Thanks!

  • 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-06-01T08:35:53+00:00Added an answer on June 1, 2026 at 8:35 am

    I would store the start and end dates as MySQL native TIME fields.
    You would need to consider ranges that span midnight as two separate ranges but you would be able to query the table like this, To find all current quiet periods

    SELECT DISTINCT name FROM `quiet_periods` 
    WHERE start_time<=CURTIME() AND CURTIME()<=end_time
    

    Or to find all non-active quiet periods

    SELECT name FROM quiet_periods WHERE name NOT IN (
      SELECT name FROM `quiet_periods` 
      WHERE start_time<=CURTIME() AND CURTIME()<=end_time
    )
    

    So with sample data

    id  --  name        -- start_time -- end_time
     1  --  late_night  -- 00:00:00   -- 08:30:00
     2  --  late_night  -- 22:00:00   -- 23:59:59
     3  --  null_period --   NULL     --   NULL
     4  --  nearly_10am -- 09:53:00   -- 09:55:00
    

    At 11pm this would return

    null_period
    nearly_10am
    

    from the second query.

    Depending on performance and how many rows you had you might want to refactor the second query into a JOIN and probably add the relevant INDEXes too.

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

Sidebar

Related Questions

The Scenario I have an ASP.NET web project. I want to be able to
Scenario: I have users that want to be able to change their username (unfortunately
I have a scenario in which I want user to be able to start
I have a scenario where I want to keep thumbnails of images on the
We have a scenario where we want to display a list of items and
I have a scenario where I want to reduce the margin of a Button
I have a scenario where i want to match specific word and then match
I have a scenario where I want to toggle series based on checkbox selection.
Scenario: I want to have an enum containing all the playing cards in a
I have the following scenario where I want to pass in string and a

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.