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?
Thanks Shripad
From your advice I've got the following. It worked fine until I added
hours and minutes to the range which are attributes 4i and 5i. I don't
get any error messages but don't get values from db either. Datetime
format in the db is 2003-10-14 12:37:51. Any suggestions would be
appreciated.
Db is Mysql. Following is the sql running for the last query:
'select paydate,payamount,credit,paymenttype,memberid from payments
where paydate between '2008-10-09T14:22:00+00:00' AND
'2008-10-10T14:22:00+00:00'
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 “?”’,
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.