Reputation: 437
I want to return results from my table that have a date less than today's date. Here is my statement:
$today = date('Y-m-d');
SELECT * FROM events WHERE STR_TO_DATE('$today', '%Y-%m-%d') > wp_eventscalendar_main.eventStartDate
I can select events in the future without a problem but when I try to select events in the past I don't get any results. My column 'eventStartDate' is set as a Date. Is there some kind of special operator I should be using for this?
Thanks,
Upvotes: 2
Views: 9124
Reputation: 10324
You probably need:
SELECT * FROM events WHERE CURDATE() > wp_eventscalendar_main.eventStartDate
MySQL tries to compare a String to a Date, which won't work reliably.
Upvotes: 2