I need to form a query in Arel which had a CAST operation earlier. The original query was like : select * from tablename where tablename.anniversary >= CAST(STR_TO_DATE(?,'%d-%m-%Y-%k-%i-%s') as DATETIME)
(the question mark is replaced by actual date in further code)
For the where condition, I am doing this :
where(tablename['anniversary']
.gteq("CAST(STR_TO_DATE(#{date_value},'%d-%m-%Y %k:%i') as DATETIME)"))
The final resulting query that I should get should have : tablename.anniversary >= '2015-07-13 16:12:00'
But I get :
tablename.anniversary >= 'CAST(STR_TO_DATE(13-09-2015 05:33PM,\'%d-%m-%Y %k:%i\') as DATETIME)'
What am I doing wrong ?
I'm not sure that understand your question, but...
First why don't you just use Ruby datetime formating
?
But if this date is a column:
Arel::Nodes::NamedFunction.new('CAST', [Model.arel_table[:column_name].as(Arel::Nodes::Quoted.new('DATETIME'))])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With