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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:14:00+00:00 2026-06-06T22:14:00+00:00

I have selected rows based on DateTime before using either: DATEADD(day, -1, GetDate()) AND

  • 0

I have selected rows based on DateTime before using either:

DATEADD(day, -1, GetDate()) AND GETDATE()

to get the latest record since yesterday, and

 DECLARE @today DATETIME = CAST(FLOOR(CAST(GETDATE() AS FLOAT)) AS DATETIME)  
DATEADD(mi, 00, DATEADD(hh, 8, @today)) AND DATEADD(hh, 9, @today)

In order to get a row that was between a certain time frame from the current day. Now I have a table that has a separate time and date column, so both of these do not work. I always get an error when I try either of the above methods saying:
“The data types time and datetime are incompatible in the greater than or equal to operator.” I know the problem is that I don’t have a DateTime type column to reference. Is there a way to get a row between a certain time frame referencing separate time and date fields? 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-06T22:14:02+00:00Added an answer on June 6, 2026 at 10:14 pm

    You can add the Date and the Time fields together to create a single date/time field with which to compare:

    create table #temp (id int, d date, t time)
    insert into #temp values (1, '1/1/2000', '1:00 PM')
    insert into #temp values (2, '1/1/2000', '2:00 PM')
    insert into #temp values (3, '1/1/2000', '3:00 PM')
    
    select * from #temp where cast(d as datetime) + cast(t as datetime) between '1/1/2000 1:10 PM' and '1/1/2000 2:30 PM'
    

    So provided your DATEADD() is setup correctly, you could do this:

    SELECT * FROM sometable WHERE cast(DateField as datetime) + cast(TimeField as datetime) BETWEEN DATEADD(mi, 00, DATEADD(hh, 8, @today)) AND DATEADD(hh, 9, @today)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP script that inserts rows into a table based on selected
I have a datagridview that may or may not have rows selected when the
I have a web based program which chooses some records from a database using
hi i have set up a php based form submission method for sorting rows
I have a PHP-based sorting method with a drop-down menu to sort rows. It
I have selected text by visual mode and pressed :. I run the following
After I have selected a range containing numerical values, I want to, via VBA,
i have a custom UITableView Cell, i have selected a particular cell and goes
I have a form which has a Combo Box Control. I have selected the
Just wondering how I can paste an object after I have selected it in

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.