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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:53:52+00:00 2026-05-18T19:53:52+00:00

I have a table with following columns (name : varchar), (mydate : DATE), (endtime

  • 0

I have a table with following columns

(name : varchar), (mydate : DATE), (endtime : TIME)

I’m trying to get specific rows based on the following conditions:

  1. mydate is within a certain range
  2. mydate > date(NOW())
  3. endTime > time(NOW()), this should apply only to “todays” date rows

The problem is with endTime. For example, consider the following data

  1. apples 2011-02-01 21:00:00
  2. orange 2011-03-02 10:00:00
  3. grapes 2011-05-10 11:00:00

If the inputs to the query are

  1. range: 2011-01-01 to 2011-04-01
  2. date(NOW()) : 2011-01-01
  3. time(NOW()) : 20:00:00

Consider the query

SELECT name FROM mytable
WHERE mydate BETWEEN  '2011-01-01' AND '2011-04-01'
AND date >= DATE(NOW()) 
AND endTime > TIME(NOW())

The query results only ‘apples’. But the correct result is ‘apples’ and ‘orange’.
The problem being condition: endTime > time(NOW()), this should apply only to “todays” date rows.

I dont want to UNION, as my original query is big.
Is there a way we can apply condition to certain rows only.

Any ideas are appreciated.
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-05-18T19:53:52+00:00Added an answer on May 18, 2026 at 7:53 pm

    Use:

    SELECT name 
      FROM mytable
     WHERE mydate BETWEEN  '2011-01-01' AND '2011-04-01'
       AND ADDTIME(mydate, endtime) > NOW()
    

    The ADDTIME function will allow you to combine the DATE and TIME value(s) into a single DATETIME, which you can then use against NOW()/CURRENT_TIMESTAMP.

    Frankly, the additional criteria is redundant…

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

Sidebar

Related Questions

I have the following code, I'm trying to get a table with 4 columns
I have a table with the following columns: id - INT UNSIGNED AUTO_INCREMENT name
I have table with following details Table name EMPLOYEE and columns EMPID (PK smallint
I have a table with the following columns: A B C --------- 1 10
I have a pictures table that has the following columns: PICTURE_ID int IDENTITY(1000,1) NOT
I have a table of users containing the following columns: | User_ID (int) |
I have a table with 3 columns: customer_name varchar ,account_type varchar ,current_balance double precision
So I have an example table called items with the following columns: item_id (int)
I have created a table in MSSQL having following structure - **Table Name -
I have two tables with the following columns: table1: id, agent_name, ticket_id, category, date_logged

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.