Reputation: 29
SELECT scandate from FPI where scandate BETWEEN '2017-07-20' and '2017-07-25' DATEPART(hh,[scandate]) >= 22 AND DATEPART(hh,[scandate]) < 6
but i get nothing ...
SELECT scandate from FPI where scandate BETWEEN '2017-07-20' and '2017-07-25' DATEPART(hh,[scandate]) >= 14 AND DATEPART(hh,[scandate]) < 22
2pm to 10pm is working but for 10pm to 6am its not working...TIA
Upvotes: 0
Views: 3059
Reputation: 29
SELECT scandate FROM FPI WHERE scandate BETWEEN '2017-07-20' and '2017-07-25' AND (DATEPART(hour, scandate) >= 22 OR DATEPART(hour, scandate) < 6)
Upvotes: 0
Reputation: 20186
use OR
,
SELECT scandate from FPI where scandate BETWEEN '2017-07-20' and '2017-07-25' DATEPART(hh,[scandate]) >= 22 OR DATEPART(hh,[scandate]) < 6;
Upvotes: 0
Reputation: 1031
You need to add one to the date:
SELECT scandate
FROM FPI
WHERE scandate BETWEEN '2017-07-20' and dateadd(day,1,'2017-07-25') AND
(DATEPART(hour, scandate) >= 22 OR DATEPART(hour, DATEADD(day,1, scandate)) < 6)
Upvotes: 0
Reputation: 1270523
You need OR
in the first query:
SELECT scandate
FROM FPI
WHERE scandate BETWEEN '2017-07-20' and '2017-07-25' AND
(DATEPART(hour, scandate) >= 22 OR DATEPART(hour, scandate) < 6)
Upvotes: 1