Ben Gordon
Ben Gordon

Reputation: 437

How can I return results less than current date?

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

Answers (2)

Ambarish Yadav
Ambarish Yadav

Reputation: 412

You can Use select from table_name where date < curdate()

Upvotes: 2

Daan
Daan

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

Related Questions