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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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")@subscriptions = find(:all, :conditions => [''subscriptions.user_id = ? AND subscriptions.confirmed = 1 AND events.start_on >= ?'', user_id, 7.days.ago.at_beginning_of_day], :joins => "INNER JOIN events on subscriptions.event_id = events.id") -philip> > 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 > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Philip, sorry for the late reply - that code works a treat! Thanks for your help, Mick -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---