Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SELECT statement filtering by time of day

Table A, columns OrderId, OrderTimeStamp (datetime).

I want to SELECT all records for any date, but between 10 am and 1 pm, for example.

How do I do that?

Thanks!

like image 706
Amarundo Avatar asked Mar 23 '12 13:03

Amarundo


1 Answers

declare @t table(d datetime)

insert @t values('2012-01-01 09:00'),('2012-01-01 10:00'),('2012-01-01 11:00')

select cast(d as time) from @t where  cast(d as time) between '10:00' and '13:00'
like image 62
t-clausen.dk Avatar answered Nov 18 '22 00:11

t-clausen.dk