I have two columns in a table
Now I want to write a query which should returns row which has time and date in future or past.
I wrote something like this
SELECT *
FROM events e
WHERE CONCAT(e.event_date, ' ', e.event_time) <= DATE_FORMAT(NOW(), '%m/%d/%Y %g:%i %a')
But it didn't work, it's just one of those things which you never know what's wrong with them
Thanks in advance!
SELECT *
FROM Events
WHERE event_date < CURRENT_DATE()
OR (event_date = CURRENT_DATE() AND event_time <= CURRENT_TIME())
This has the advantage of using any index that might exist on event_date
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With