Ben Johnson
2006-Jul-25 21:37 UTC
[Rails] Subtract a field from the current time in MySQL?
I have the following: Table Products: With a column called "purchased_at" of type "datetime". Products.find(:all, :conditions => ["? - purchased_at >= 120", Time.now]) Why doesn''t that work? What I''m trying to do is find records that were purchased less than or equal to 2 minutes ago. Thanks for your help. -- Posted via http://www.ruby-forum.com/.
Jean-François
2006-Jul-25 21:55 UTC
[Rails] Subtract a field from the current time in MySQL?
Hello Ben,> Table Products: > With a column called "purchased_at" of type "datetime". > > Products.find(:all, :conditions => ["? - purchased_at >= 120", > Time.now]) > > Why doesn''t that work? What I''m trying to do is find records that were > purchased less than or equal to 2 minutes ago.Try sth like : Product.find(:all, :conditions => [ "purchased_at > ?", 2.minutes.ago.to_s(:db) ]) -- Jean-Fran?ois. -- ? la renverse.
Ben Johnson
2006-Jul-26 00:10 UTC
[Rails] Re: Subtract a field from the current time in MySQL?
Ben Johnson wrote:> I have the following: > > Table Products: > With a column called "purchased_at" of type "datetime". > > Products.find(:all, :conditions => ["? - purchased_at >= 120", > Time.now]) > > Why doesn''t that work? What I''m trying to do is find records that were > purchased less than or equal to 2 minutes ago. > > Thanks for your help.I found the following to work: Products.find(:all, :conditions => "NOW() - purchased_at >= 120" Just udating it for later searches. -- Posted via http://www.ruby-forum.com/.
Rolando Abarca
2006-Jul-26 00:28 UTC
[Rails] Re: Subtract a field from the current time in MySQL?
> I found the following to work: > Products.find(:all, :conditions => "NOW() - purchased_at >= 120" > > Just udating it for later searches.SELECT something FROM tbl_name WHERE DATE_SUB(CURDATE(),INTERVAL 2 MINUTES) <= date_col; so your find should be like this: Products.find(:all, :conditions => "DATE_SUB(CURDATE(),INTERVAL 2 MINUTES) >= purchased_at") Interval can be something like 2 MINUTES. More info: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html regards, rolando.- -- Posted via http://www.ruby-forum.com/.
Michael Schreifels
2006-Jul-26 00:31 UTC
[Rails] Subtract a field from the current time in MySQL?
On 7/25/06, Ben Johnson <bjohnson@mediamanifest.com> wrote:> I have the following: > > Table Products: > With a column called "purchased_at" of type "datetime". > > Products.find(:all, :conditions => ["? - purchased_at >= 120", > Time.now]) > > Why doesn''t that work? What I''m trying to do is find records that were > purchased less than or equal to 2 minutes ago. > > Thanks for your help.What about this? Products.find(:all, :conditions => ["(? - purchased_at) >= 120", Time.now]) Does this work? Should result in a query like this: SELECT * FROM products WHERE (the_current_datetime_here - purchased_at) >= 120 Hope that helps.
Abdur-Rahman Advany
2006-Jul-31 21:51 UTC
[Rails] Strange error with both webrick and mongrel
Hi peepz, I have quite a strange problem, when I visit my rails application in internet explorer sometimes it won''t complete the page and just give aerror. I saw that disabling external extensions fixes the problems but it won''t. Firefox just workes fine. Mongrel doesn''t give a stackstrace only invalid argument error that why I listed the webrick error below... It gives errors like: 127.0.0.1 - - [31/Jul/2006:23:47:42 W. Europe Standard Time] "GET /images/edit.gif?1154286828 HTTP/1.1" 304 0 [2006-07-31 23:47:42] ERROR Errno::EINVAL: Invalid argument C:/Program Files/ruby/lib/ruby/1.8/webrick/httpresponse.rb:324:in `write'' C:/Program Files/ruby/lib/ruby/1.8/webrick/httpresponse.rb:324:in `_write_data'' C:/Program Files/ruby/lib/ruby/1.8/webrick/httpresponse.rb:180:in `send_header'' C:/Program Files/ruby/lib/ruby/1.8/webrick/httpresponse.rb:103:in `send_response'' C:/Program Files/ruby/lib/ruby/1.8/webrick/httpserver.rb:79:in `run'' C:/Program Files/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'' C:/Program Files/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'' C:/Program Files/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start'' C:/Program Files/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start'' C:/Program Files/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start'' C:/Program Files/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'' ./script/../config/../vendor/rails/railties/lib/webrick_server.rb:67:in `dispatch'' ./script/../config/../vendor/rails/railties/lib/commands/servers/webrick.rb:59 C:/Program Files/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'' ./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:147:in `require'' ./script/../config/../vendor/rails/railties/lib/commands/server.rb:39 C:/Program Files/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'' ./script/server:3 -e:4 anyone know whats wrong? Abdul
Abdur-Rahman Advany
2006-Jul-31 22:53 UTC
[Rails] Strange error with both webrick and mongrel
Strange, now I just get half generated pages in both internet explorer and firefox.... Abdur-Rahman Advany wrote:> Hi peepz, > > I have quite a strange problem, when I visit my rails application in > internet explorer sometimes it won''t complete the page and just give > aerror. I saw that disabling external extensions fixes the problems > but it won''t. Firefox just workes fine. > > Mongrel doesn''t give a stackstrace only invalid argument error that > why I listed the webrick error below... > > It gives errors like: > > 127.0.0.1 - - [31/Jul/2006:23:47:42 W. Europe Standard Time] "GET > /images/edit.gif?1154286828 HTTP/1.1" 304 0 > [2006-07-31 23:47:42] ERROR Errno::EINVAL: Invalid argument > C:/Program Files/ruby/lib/ruby/1.8/webrick/httpresponse.rb:324:in > `write'' > C:/Program Files/ruby/lib/ruby/1.8/webrick/httpresponse.rb:324:in > `_write_data'' > C:/Program Files/ruby/lib/ruby/1.8/webrick/httpresponse.rb:180:in > `send_header'' > C:/Program Files/ruby/lib/ruby/1.8/webrick/httpresponse.rb:103:in > `send_response'' > C:/Program Files/ruby/lib/ruby/1.8/webrick/httpserver.rb:79:in `run'' > C:/Program Files/ruby/lib/ruby/1.8/webrick/server.rb:173:in > `start_thread'' > C:/Program Files/ruby/lib/ruby/1.8/webrick/server.rb:162:in > `start_thread'' > C:/Program Files/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start'' > C:/Program Files/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start'' > C:/Program Files/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start'' > C:/Program Files/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'' > > ./script/../config/../vendor/rails/railties/lib/webrick_server.rb:67:in > `dispatch'' > > ./script/../config/../vendor/rails/railties/lib/commands/servers/webrick.rb:59 > > C:/Program > Files/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in > `require'' > > ./script/../config/../vendor/rails/activesupport/lib/active_support/dependencies.rb:147:in > `require'' > ./script/../config/../vendor/rails/railties/lib/commands/server.rb:39 > C:/Program > Files/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in > `require'' > ./script/server:3 > -e:4 > > > anyone know whats wrong? > > Abdul > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >