[英]Order by date in mysql not displaying results with today's date
I have the following code to order results based on date closest to todays and including todays. 我有以下代码根据最接近今天(包括今天)的日期对结果进行排序。 The problem im having is that events with todays date are not displaying.
我的问题是没有显示具有今天日期的事件。
All the other dates are displaying in order 所有其他日期按顺序显示
Heres my code: 这是我的代码:
"SELECT * FROM event WHERE `status` = 'open' AND event_date >= NOW() ORDER BY event_date"
Many thanks 非常感谢
SO the answer is... 所以答案是...
SELECT *
FROM event
WHERE `status` = 'open'
AND event_date >= curdate()
ORDER BY event_date
Reason as stated by Marc B and xQbert: 正如Marc B和xQbert所述:
Now() includes time. Now()包含时间。 To get all records for today you have to use something that has midnight as the starting value which
curdate()
does. 要获取今天的所有记录,您必须使用
curdate()
的起始值为午夜的内容。 Alternatively you could convert the now() to a value without time but that has overhead. 或者,您可以将now()转换为没有时间的值,但这会产生开销。
curdate()
seems to meet the need. curdate()
似乎可以满足需要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.