Answer the question
In order to leave comments, you need to log in
How to use created_at field in Ruby on Rails in mysql query?
Usually this thing works STR_TO_DATE(string, '%d.%m.%Y'), example:
Post.where("STR_TO_DATE('02.11.2016', '%d.%m.%Y') < STR_TO_DATE('01.01.2017', '%d.%m.%Y')")
Post.where("STR_TO_DATE(created_at, '%d.%m.%Y') < STR_TO_DATE('01.01.2017', '%d.%m.%Y')")
Answer the question
In order to leave comments, you need to log in
From the comments, created_at is a normal timestamp or datetime field. Therefore, not only does it not need to be cast to a string and parsed again into a date (with the wrong format, moreover), but it is also very harmful to do so, because precludes the use of an index.
The date can be formatted in Ymd format on the application, this is already more convenient.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question