Amit Patil
Amit Patil

Reputation: 1993

How to get record in between time range

I want to fetch some result from table depending on time range so i did

SELECT * FROM TABLE where convert(varchar(10),CountryTime,108) between '15:00' and '16:00'

CountryTime- is of varchar type.. but iam not getting corect output plz suggets..

Upvotes: 1

Views: 3100

Answers (2)

Michael Pakhantsov
Michael Pakhantsov

Reputation: 25370

Use varchar(5) instead of varchar(8)

  SELECT * 
  FROM TABLE 
  where convert(varchar(5),CountryTime,108) between '15:00' and '16:00' 

Upvotes: 1

krock
krock

Reputation: 29619

Try using the DATEPART function:

SELECT * FROM TABLE
where DATEPART(HOUR, CountryTime) IN (15, 16)

Upvotes: 2

Related Questions