0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Railsで「現在から三日前まで」などの期間指定の方法

Posted at

Railsで期間指定の方法を検索すると、1日前(.yesterday)とか一日の開始時(.beginning_of_day)とか今日一日(.all_day)とか今週いっぱい(.all_week)…などはやまほどひっかかるが、「現在から三日前までの範囲」などの指定はぜんぜん出てこない。検索の仕方が悪いのかもしれないが。

一応描いておくと

Model.where(created_at: Time.now - 3.days..Time.now)

といった感じで、..を挟んで前に過去(例では現時点から三日前)の時間指定、後ろに後の時間(例では現在)をおくだけ。簡単だけど、案外全然出てこないので困ってたので備忘録としてかいておきます。今日の00時以降だとか、今週だけとかは他に一杯あるのでそっちを参考にしてください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?