查询时间在两次之间的行(mysql)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28423067/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Query rows where time is between two times (mysql)
提问by Code Diary
I need to query all entries from January 1 to January 31. But only between 6am to 10am for each day. I should do it in Mysql.
我需要查询从 1 月 1 日到 1 月 31 日的所有条目。但每天只能在早上 6 点到早上 10 点之间查询。我应该在Mysql中做到这一点。
Please help. Thank you!
请帮忙。谢谢!
回答by Barmar
Use the BETWEEN
operator to match between values. And use the HOUR()
function to get the hour out of the dates.
使用BETWEEN
运算符在值之间进行匹配。并使用该HOUR()
函数从日期中获取小时。
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
回答by Fahad Bhuyian
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'