Rails 5.1 has introduced Date#all_day helper | BigBinary Blog

Ask questions Research chat →

https://www.bigbinary.com/blog/rails-5-1-has-introduced-date-all_day-helper · scraped

rails ruby

Attachments

Scraped Content

— 110 words · 2026-02-14 03:12:12 UTC ·

Excerpt

Sometimes, we want to query records over the whole day for a given date. >> User.where(created_at: Date.today.beginning_of_day..Date.today.end_of_day) => SELECT "users".* FROM "users" WHERE ("users"."created_at" BETWEEN $1 AND $2) [["created_at", 2017-04-09 00:00:00 UTC], ["created_at", 2017-04-09 23:59:59 UTC]] Rails 5.1 has introduced a helper method for creating this range object for a given date in the form of Date#all_day. >> User.where(created_at: Date.today.all_day) => SELECT "users".* FROM "users" WHERE ("users"."created_at" BETWEEN $1 AND $2) [["created_at", 2017-04-09 00:00:00 UTC], ["created_at", 2017-04-09 23:59:59 UTC]] We can confirm that the Date#all_day method returns the range object for a given date. >> Date.today.all_day => Sun, 09 Apr 2017 00:00:00 UTC +00:00..Sun, 09 Apr 2017 23:59:59 UTC +00:00
Sometimes, we want to query records over the whole day for a given date. >> User.where(created_at: Date.today.beginning_of_day..Date.today.end_of_day) => SELECT "users".* FROM "users" WHERE ("users"."created_at" BETWEEN $1 AND $2) [["created_at", 2017-04-09 00:00:00 UTC], ["created_at", 2017-04-09 23:59:59 UTC]] Rails 5.1 has introduced a helper method for creating this range object for a given date in the form of Date#all_day. >> User.where(created_at: Date.today.all_day) => SELECT "users".* FROM "users" WHERE ("users"."created_at" BETWEEN $1 AND $2) [["created_at", 2017-04-09 00:00:00 UTC], ["created_at", 2017-04-09 23:59:59 UTC]] We can confirm that the Date#all_day method returns the range object for a given date. >> Date.today.all_day => Sun, 09 Apr 2017 00:00:00 UTC +00:00..Sun, 09 Apr 2017 23:59:59 UTC +00:00

Visibility

Visible to everyone

Reading Status

Related Bookmarks

My Note


Saved!

Annotations

Export as Markdown
+ Annotate selection

Add Annotation