SQL Datepart and Convert DATETIME functions

I am trying to get a query to work. I have a table that includes a column REQDATE that is a datetime type. I need to return all records for a span of time REQDATE between '03/30/2009' and '04/06/2009'. With the records returned I need to return all the records where the time is between 17:00:00 hours and 08:00:00 hours. I am having trouble with this part. The datetime is written like 08:00:00 AM, not in 24-hour time.

SELECT *
FROM TASKS
WHERE (DATEPART(hh, REQDATE) BETWEEN '17:00:00' AND '08:00:00') AND (REQDATE BETWEEN CONVERT(DATETIME, '2009-03-30 00:00:00', 102)
AND CONVERT(DATETIME, '2009-04-06 00:00:00', 102))

WHERE
(datepart(hh,REQDATE)+':'+datepart(ss,REQDATE)+':'+datepart(ss,REQDATE)) BETWEEN '17:00:00' AND '08:00:00'
and
REQDATE BETWEEN CONVERT(DATETIME, '2009-03-30 00:00:00', 102)
AND CONVERT(DATETIME, '2009-04-06 00:00:00', 102))

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Featured Post

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.