Reputation: 427
I need to query all entries from January 1 to January 31. But only between 6 am to 10 am for each day. I should do it in MySQL.
Upvotes: 5
Views: 43392
Reputation: 325
You can also use this query to get all rows.
SELECT * FROM `attendance_raw` WHERE date>='2016-09-08 10:00:00' AND date<='2016-09-09 06:00:00'
Upvotes: 2
Reputation: 780724
Use the BETWEEN
operator to match between values. And use the HOUR()
function to get the hour out of the dates.
SELECT *
FROM table
WHERE date BETWEEN '2015-01-01 00:00' AND '2015-01-31 23:59:59'
AND HOUR(date) BETWEEN 6 AND 10
Upvotes: 30