On 9 Oct 2008, at 09:18, mahmoud said wrote:

> Greetings Everyone..
>
> In the conditions of your query you should pass the parameters as  
> simple strings.
> User strftime to get the desired string representation while passing  
> it to the query
> I'd try this:
>
> @orders=Order.find(:all,:conditions => ['created_at BETWEEN "?" AND  
> "?"',
> start_date.strftime('%Y-%m-%d %H:%M:%S'), end_date.strftime('%Y-%m- 
> %d %H:%M:%S')])
>
> the format above is the one u mentioned as the default of your  
> database engine "Format in db is 2003-10-14 12:37:51"
>

Looks like you're using rails 1.1 or earlier. In more recent versions  
of rails you don't need to do any of this:

Order.find(:all,:conditions => ['created_at BETWEEN ?  
AND ?',start_date, end_date])
would just work

start_date.to_s(:db) might work, but I really can't remember what  
works on really old versions of rails.

Fred



>
>
>
> On Mon, Oct 6, 2008 at 1:16 PM, Katsuo Isono <[EMAIL PROTECTED] 
> > wrote:
>
> I am having difficulty passing datetime values to a method in the
> controller. I get sql syntax error from the following. Can someone
> advise me what I am doing wrong?
>
> my view:
>
>   <table>
>     <tr>
>       <%= start_form_tag :action => 'time_range' %>
>       <td ><%=  datetime_select("sd", "time_range") %></td>
>       <td ><%=  datetime_select("ed", "time_range") %></td>
>       <td><%= submit_tag 'go'%></td>
>     </tr>
>   </table>
>
> my method:
>
> def time_range
> start_date=params[:sd]
> end_date=params[:ed]
> @orders=Order.find(:all,:conditions => ['created_at BETWEEN ? AND ?',
> start_date, end_date])
>
> end
> --
> Posted via http://www.ruby-forum.com/.
>
>
>
>
>
> -- 
> Mahmoud Said
> Software Developer
> blog.modsaid.com
> www.eSpace.com.eg
> +20-16-1223857
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
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@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to