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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:18:11+00:00 2026-05-18T00:18:11+00:00

I need to select all records from my SQL Server database that falls between

  • 0

I need to select all records from my SQL Server database that falls between a certain hour. Let me give you an example:

Current time is 9:33 am and you have numerous Program records in the database that have an ProgramStart and ProgramEnd. An example of the dates might be:

 | ProgramStart             | ProgramEnd              | ClientID |
 +--------------------------+-------------------------+----------+
 | 1900-01-01 09:00:00.000  | 1900-01-01 10:00:00.000 | 5        |
 +--------------------------+-------------------------+----------+
 | 1900-01-01 11:00:00.000  | 1900-01-01 13:00:00.000 | 4        |
 +--------------------------+-------------------------+----------+
 | 1900-01-01 12:00:00.000  | 1900-01-01 14:00:00.000 | 5        |
 +--------------------------+-------------------------+----------+
 | 1900-01-01 11:00:00.000  | 1900-01-01 13:00:00.000 | 6        |
 +--------------------------+-------------------------+----------+
 | 1900-01-01 16:00:00.000  | 1900-01-01 17:00:00.000 | 7        |
 +--------------------------+-------------------------+----------+
 | 1900-01-01 16:00:00.000  | 1900-01-01 17:00:00.000 | 5        |
 +--------------------------+-------------------------+----------+
 | 1900-01-01 17:00:00.000  | 1900-01-01 18:00:00.000 | 4        |
 +--------------------------+-------------------------+----------+

I want to extract all records for client 5 and between the current time which is 9:33am

How does one do that with SQL. I tried this, but it doesn’t work:

 SELECT CAST('1900-01-01 09:33:00.000' AS datetime) AS TimeNow, * FROM Programs
 WHERE ClientID = 5
 AND TimeNow BETWEEN '1900-01-01 09:00:00.000' AND '1900-01-01 10:00:00.000'

any suggestions would be greatly appreciated.

Many thanks,
Paul

  • 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-18T00:18:11+00:00Added an answer on May 18, 2026 at 12:18 am
    select *
        from Programs
        where ClientId = 5
            and DATEADD(Day, 0-DATEDIFF(Day, 0, GetDate()), GetDate()) between ProgramStart and ProgramEnd
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to transfer a large number of rows from a SQL Server database
Ok I have a table in my SQL Server database that stores comments. My
I have two tables in an MS SQL Server 2005 database, parent and child,
I have a very dynamic SQL Server problem to solve. I am developing a
I am new to ADO.net and have this problem: Let's assume I have these
I'm building a heavily CRUD based ASP.NET website and I've got to the phase
I'm working on a legacy project, written for the most part in Delphi 5
NEWEST EDIT!!! PLEASE... I have been through many permutations of this code. I am
In the application I'm working on porting to the web, we currently dynamically access
Not sure if I can do it this way. I want to get current

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.