Hi, I am trying to return all the records in my table for which a date
comparison reveals that that date is within 7 days. The code I have
written looks like this:
@subscriptions = find(:all, :conditions => [‘subscriptions.user_id = ?
AND subscriptions.confirmed = 1 AND (DATEDIFF(day,now(),events.start_on)
< 7)’,user_id], :joins => “INNER JOIN events on subscriptions.event_id =
events.id”)
However it throws a nasty SQL error and no matter what I do I can’t seem
to resolve it.
FYI the error is this:
Mysql::Error: #42000You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near ‘:day,now(),events.start_on) < 7))’ at line 1: SELECT
- FROM subscriptions INNER JOIN events on subscriptions.event_id =
events.id WHERE (subscriptions.user_id = 1 AND subscriptions.confirmed =
1 AND (DATEDIFF(:day,now(),events.start_on) < 7))
Can anyone give me any clues?!
Much appreciated,
Mick