3
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?

昨日の時間を指定するときの注意点

Posted at

初めに

疑問に思ったことや上手くいかなかったことのアウトプットをしています。
自分なりの理解でアウトプットしていきます。初学者なので誤りもあると思います。
その際はご指摘いただけると幸いです。

モデルのscopeなどで昨日全体を指定する時

失敗例

 scope :exampled_at_yesterday, -> { where(exampled_at: 1.day.ago) }

このように1.day.agoだけの場合、昨日の中の限定された時間帯のみになってしまいます。

成功例

scope :exampled_at_yesterday, -> { where(exampled_at: 1.day.ago.all_day) }

上記のように、all_dayをつけることで昨日の0時~23時59分までを指定できます。

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
3
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?