I need to do a query on Rails model time stamps (created_at
and updated_at
) finding all records after a specified date. When executing the query:
Item.where("created_at > :date OR updated_at > :date", date: "2011-05-29")
> SELECT "items".* FROM "items" WHERE (created_at > '2011-05-29' OR updated_at > '2011-05-29')
It includes records like:
attributes:
created_at: 2011-05-29 16:07:10.664227
updated_at: 2011-05-29 16:07:10.664229
However, this date isn't greater than the one specified. Any simple way to fix this query? Thanks.
Edit:
I've also tried doing:
Item.where("created_at > :date OR updated_at > :date", date: "2011-05-29 16:07:10")
With the same result, however adding the fraction of seconds stamp as well gives the correct result.
Say you want records starting 30th May:
Then search for records that are >= 2011-05-30 00:00:00
:
some_date = Time.now
Item.where("created_at >= :date OR updated_at >= :date", date: some_date.tomorrow.beginning_of_day)
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