user11381786
user11381786

Reputation: 33

How to get data based on today date and time?

select * from hockey_stats where game_date between '11/3/2012 12:00:00' and '11/5/2012 15:00:00' order by game_date desc;

How to get data based on today date and time between 12:00:00 to 15:00:00?

Upvotes: 1

Views: 80

Answers (1)

Thom A
Thom A

Reputation: 95561

How about:

game_date BETWEEN CONVERT(varchar(10),GETDATE(),121) + 'T12:00:00' AND CONVERT(varchar(10),GETDATE(),121) + 'T15:00:00'

Note, however, I recommend using >= and < syntax when using times. I assume you wants all times after 12:00 and before 15:00, which would be:

WHERE game_date >= CONVERT(varchar(10),GETDATE(),121) + 'T12:00:00'
  AND game_date <= CONVERT(varchar(10),GETDATE(),121) + 'T15:00:00'

This does assume that game_date is a datetime (or variant) datatype, and not a varchar; but then why would it not be?

Upvotes: 2

Related Questions