After fixing production mode now I ran into a strange problem. I want
to filter out records earlier than current time. I use DateTime to
substitution. And SELECT failed after I inserted this filter "created
on > ''#{DateTime.now}''. I realized DateTime.to_s replaces a
space
character to letter T.
[4;33mChatEvent Load (0.000000) [1;37m#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 '':18:18+0200
order by created_at DESC'' at line 1: SELECT * FROM chat_event WHERE
ev_type = 0 and chat_id = 67 and created_at > 2005-06-13T22:18:18
+0200 order by created_at DESC
Look at this: created_at > 2005-06-13T22:18:18+0200
There is a T between date and time.
How can I fix this?
Gábor
PS.: Rails + MySQL (ruby ver)
On 2005.06.13., at 22:22, Gábor SEBESTYÉN wrote:> ''#{DateTime.now}''.Quick solution: DateTime.now.to_s.gsub(/T/, " "). Is it barbaric? :)) Gábor _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Quicker solution: "created on > now()" Tyler On 6/13/05, Gábor SEBESTYÉN <segabor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On 2005.06.13., at 22:22, Gábor SEBESTYÉN wrote: > > > ''#{DateTime.now}''. > Quick solution: DateTime.now.to_s.gsub(/T/, " "). Is it barbaric? :)) > > Gábor > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
Another solution:
"created on >
''#{DateTime.now.to_formatted_s(:db)}''"
This one comes from ActiveSupport::CoreExtensions::Time::Conversions
Duane Johnson
(canadaduane)
On 6/14/05, Duane Johnson <duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Another solution: > > "created on > ''#{DateTime.now.to_formatted_s(:db)}''"Hey guys, it gets even easier, the adapters know how to format the dates, you just tell them what you want. Model.find(:all, :conditions=> ["created_on > ?", DateTime.now]) -- Cheers Koz
hi how would this work with sqlite3, it doesn''t have a now() function. using the previous solution i get a syntax error. syntax error: SELECT * FROM products WHERE date_available <= 2005-06-21 10:46:13+0200 ORDER BY date_available desc any ideas thx cornelius On Jun 13, 2005, at 10:52 PM, Tyler Kiley wrote:> Quicker solution: > > "created on > now()" > > Tyler > > On 6/13/05, Gábor SEBESTYÉN <segabor-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> >> >> On 2005.06.13., at 22:22, Gábor SEBESTYÉN wrote: >> >> >> ''#{DateTime.now}''. >> Quick solution: DateTime.now.to_s.gsub(/T/, " "). Is it barbaric? :)) >> >> Gábor >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> >> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >Cornelius Jaeger, Member of Visual FOOD GmbH - Software and Multimedia Solutions http://www.screenfood.ch http://www.visualfood.ch Moosstrasse 7 CH-6003 Lucerne SWITZERLAND Fon: +41 (0)41 21 0 21 41 Fax: +41 (0)41 21 0 21 43 iChat or AIM nelius-ee4meeAH724@public.gmane.org _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails