I am trying to create a filter to see anything happening during a certain period of time of day using my datetime variable which has the date and time in format like this:
2009-07-30 16:05:15
How I can create a WHERE clause that will let me look at any entries where the timestamp of that variable is between certain hours such as 17:00:00 and 07:00:00 the following day.
Which Imagine would be two separate clauses starting
> 17:00:00 OR < 07:00:00 respectively
Use DATEPART function
WHERE DATEPART(hh, [Date Column]) between 7 and 17
or
WHERE NOT DATEPART(hh, [Date Column]) between 7 and 17
for the night
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With