Hiren
Hiren

Reputation: 1391

SQL Get data from time duration

I have a SQL database in which I have a column with DataType DateTime. Now I want particular data with particular time duration of all dates. For example, I want data between 7 o'clock and 8 o'clock from all dates, is there any way?

Upvotes: 3

Views: 364

Answers (1)

D'Arcy Rittich
D'Arcy Rittich

Reputation: 171351

For SQL Server, you can do:

select *
from MyTable
where datepart(hour, MyDateColumn) between 19 and 20

For MySQL:

select *
from MyTable
where EXTRACT(HOUR FROM MyDateColumn) between 19 and 20

Upvotes: 5

Related Questions