[英]MySQL select dependant on time of day
I want to select from a MySQL table and filter depending on the time of day: 我想从MySQL表中选择并根据一天中的时间进行过滤:
if now > 10am select uploaded date where created date is today
if now < 10am select uploaded date where created date is yesterday
This should do what you need. 这应该做您需要的。
SELECT
`uploaded_date`
FROM
`table`
WHERE
`created_date` = CASE WHEN CURTIME() > 100000
THEN CURDATE()
ELSE CURDATE() - INTERVAL 1 DAY
END
You can see a similar example in this fiddle which should return a single row of "AM" in the morning, "Noon" at noon, and "PM" in the afternoon (and 2 empty result sets). 您可以在此提琴中看到一个类似的示例, 该示例应在早上返回一行“ AM”,在中午返回“ Noon”,在下午返回“ PM”(以及两个空结果集)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.