1

Possible Duplicate:
Specific Time Range Query in SQL Server

For example I have 3 rows:

Id      Date
1       '2011-01-02 09:14:23.0000000' 
2       '2011-02-15 10:15:47.0000000' 
3       '2011-03-18 21:12:33.0000000' 

And I whant to take only rows, where TIME between 09:00 and 11:00 and any date.

I need this in result set:

 Id      Date
    1       '2011-01-02 09:14:23.0000000' 
    2       '2011-02-15 10:15:47.0000000' 

Thanks

Community
  • 1
  • 1
Ang
  • 35
  • 2
  • 3
  • 8

1 Answers1

4

Here's one approach

SELECT id, date 
FROM myTable 
WHERE CONVERT(VARCHAR(8),Date,108) between '09:00:00' and '11:00:00'
Code Magician
  • 23,217
  • 7
  • 60
  • 77
  • DATEPART(hh, Date) BETWEEN 9 and 11 - select date with 11:45 time - it is wrong – Ang Aug 11 '11 at 07:25