user3741713 user3741713 - 6 months ago 26
SQL Question

rails convert datetime to date within a scope

In my model I defined the following scope:

scope :today, -> { where time_start: }

This is not working because I'm comparing a mysql datetime against a date.
I am trying to do the equivalent of the date() mysql function (extracting a date from a datetime).


Try this:

scope :today, -> { where time_start: }

Using range in criteria will generate a BETWEEN query, something like this:

SELECT "models".* FROM "models"
    WHERE (
        "models"."time_start" BETWEEN
            '2016-07-29 00:00:00.000000' AND '2016-07-29 23:59:59.999999'