简体   繁体   English

MySQL选择一天中的时间与日期无关

[英]MySQL select times of day independent of date

Let's say I have the below records what i want to do is select the records based on their time of day independent of month, year or day. 假设我有以下记录,我想要做的就是根据其一天中的时间选择记录,而与月,年或日无关。 In short " select all records between 12:00 and 14:00" and it should return me A and D. How can I do that? 简而言之,“选择12:00至14:00之间的所有记录”,它应该返回A和D。我该怎么做?

A 2012-10-24 12:00:00
B 2012-13-25 03:00:00
C 2012-12-25 20:00:00
D 2012-16-26 14:00:00

Try this : 尝试这个 :

SELECT *
FROM table
WHERE HOUR(date) BETWEEN 12 AND 14

read more about this function here(w3 resource) 在此处阅读有关此功能的更多信息(w3资源)

If you want based on hour and minute, then you need TIME() function. 如果要基于小时和分钟,则需要TIME()函数。

syntax : WHERE TIME(datetime) >= '18:00:00' 语法: WHERE TIME(datetime) >= '18:00:00'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM