简体   繁体   English

从小时开始获取今天的mySQL行

[英]Get mySQL rows from today using the hour

Is it possible to SELECT all rows from just today using DATE('today') and then grab rows based on a specified hour? 是否可以使用DATE('today')从今天开始SELECT所有行,然后根据指定的小时获取行?

I'm assuming it'd be something like so? 我以为是这样吗? (I know it's not the correct syntax) (我知道这不是正确的语法)

SELECT 
    *
FROM
    `table`
WHERE
    DATE(`datetime`) = DATE(`today`) 
AND
    HOUR(`datetime`) = '23'

Bare in the mind the datetime column is in datetime format 请注意, datetime列采用datetime格式

You can use NOW() to get the current datetime, or CURDATE() to get the date only, and then the DATE() and HOUR() functions: 您可以使用NOW()获取当前日期时间,或使用CURDATE()仅获取日期,然后使用DATE()HOUR()函数:

SELECT *
FROM my_table
WHERE DATE(my_datetime_field) = CURDATE() /* or DATE(NOW()) */
AND HOUR(my_datetime_field) = 23;

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

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