Reputation: 2240
I am trying to pull a report from my DB ( mySQL ).
From 9am to 9pm.
By schema has the dates in DATETIME ( MM-DD-YYYY HH:MM:SS )
``` SQL
SELECT COUNT(*) FROM table_name
WHERE date_created BETWEEN '09:00:00' AND '21:00:00'
thoughts? Do I have to cast the DATETIME into something else?
Upvotes: 1
Views: 41
Reputation: 3508
You need to just get the hours:
SELECT COUNT(*) FROM table_name
WHERE DATEPART(HOUR, date_created) BETWEEN 9 AND 21
Upvotes: 4