1

i have this date's & Time's:

date1: 10/04/2010 - Time: 08:09

date2: 11/04/2010 - Time: 08:14

i need to show all the date's between 10/04/2010 time 06:00 and 11/04/2010 time 6:00

i write this: select * from MyTbl where ((Tdate BETWEEN '20100410' AND '20100411') and (Ttime BETWEEN '06:00' and '06:00'))

but i get empty table

thank's in advance

2
  • what data type is Tdate and Ttime? Commented Apr 12, 2010 at 6:55
  • Tdate and Ttime are datetime type Commented Apr 12, 2010 at 7:03

4 Answers 4

3

If both columns are datetime, simply add them so you can do a "proper" range query

where Tdate +Ttime BETWEEN '2010-04-10 06:00:00' AND '2010-04-11 06:00:00'
Sign up to request clarification or add additional context in comments.

1 Comment

+1 for Tdate +Ttime and then using the "BETWEEN". Saves atleast 2 more lines. :-)
1

That's not correct.

What your resultset returns is all the records that are valid between 10/04/2010 06:00 - 10/04/2010 06:00 or 11/04/2010 06:00 - 11/04/2010 06:00.

(Which means there are exactly 2 valid minutes for records to be retrieved).

You need to filter according to the full date including time.

Comments

1

Find total number of orders that were placed in each month of the year 1987.

SELECT COUNT(OrdId) AS TotalNumberOfOrder FROM OrderABC WHERE OrdDate > '1987-01-01' AND OrdDate < '1987-12-31';

or

SELECT COUNT(OrdId) AS TotalNumberOfOrder FROM OrderABC WHERE OrdDate BETWEEN '1987-01-01' AND '1987-12-31'; 

Comments

0

I think you are looking for this:

select * 
from MyTbl 
where (Tdate = '20100410' AND Time >= '06:00') 
   OR (TDATE > '20100410' AND TDATE < '20100410')
   OR (Tdate = '20100411' AND Time <= '06:00')

2 Comments

do you think that will really work? You can use 'AND' instead.
select * from MyTbl where (Tdate = '20100410' AND Time >= '06:00') AND (Tdate > '20100410' AND TDATE < '20100410') AND (Tdate = '20100411' AND Time <= '06:00')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.