sql - Search for database objects created on a specific day? - Stack Overflow

Ask questions Research chat →

https://stackoverflow.com/questions/19733736/search-for-database-objects-created-on-a-specific-day · scraped

rails

Attachments

Scraped Content

— 105 words · 2026-02-14 02:56:46 UTC ·

Excerpt

I would do the cast on the database and select the current date there, instead of doing it with a range. You can do this with DATE(created_at) (Will result in "2013-11-01") Then inject the param in the where: Model.where("DATE(created_at) = ?", Date.today) If it's used on more places then one it would be good to create a scope as Morner suggested: scope :created_today { where("DATE(created_at) = ?", Date.today) } with name: scope :created_today_with_name lambda do |name| where("DATE(created_at) = ? AND name = ?", Date.today, name) end or chain it: scope :created_today_with_name lambda do |name| where("DATE(created_at) = ?", Date.today).where(name: name) end Then call it as: Model.created_today_with_name('Joe')
I would do the cast on the database and select the current date there, instead of doing it with a range. You can do this with DATE(created_at) (Will result in "2013-11-01") Then inject the param in the where: Model.where("DATE(created_at) = ?", Date.today) If it's used on more places then one it would be good to create a scope as Morner suggested: scope :created_today { where("DATE(created_at) = ?", Date.today) } with name: scope :created_today_with_name lambda do |name| where("DATE(created_at) = ? AND name = ?", Date.today, name) end or chain it: scope :created_today_with_name lambda do |name| where("DATE(created_at) = ?", Date.today).where(name: name) end Then call it as: Model.created_today_with_name('Joe')

Visibility

Visible to everyone

Reading Status

Related Bookmarks

My Note


Saved!

Annotations

Export as Markdown
+ Annotate selection

Add Annotation