I would like to compare a date entered in a search field (e.g., 04.07.2012) with a date from my table (a datetime column called date). However, I can't seem to get my SQL query straight.
What I tried:
find(:all, :conditions => ['\'to_timestamp(date, \'DD Mon YYYY\')\' LIKE \'to_timestamp(?, \'DD Mon YYYY\')\'', '#{query}'])
but it fails:
PG::Error: ERROR: syntax error at or near "DD"
LINE 1: ...s".* FROM "projects" WHERE ('to_timestamp(date, 'DD Mon YYY...
^
: SELECT "pacients".* FROM "projects" WHERE ('to_timestamp(date, 'DD Mon YYYY')' LIKE 'to_timestamp('#{query}', 'DD Mon YYYY')')
I'm a real novice as far as (postgre)SQL is concerned and I would really appreciate some hints in the right direction of writing this query.
Thanks a million!
timestampanddatein PostgreSQL.