简体   繁体   中英

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:

Now() includes time. To get all records for today you have to use something that has midnight as the starting value which curdate() does. Alternatively you could convert the now() to a value without time but that has overhead. curdate() seems to meet the need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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