Why does a Time math calculation return one value in IRB but sends a diff value to SQL?
问题 I have a method in my Post model that looks like this: def self.num_posted_x_days_ago(n) start_date = Time.now.midnight - n.day end_date = Time.now.midnight - (n+1).day where(created_at: start_date..end_date).count end When I run it in IRB, I get this: > Post.num_posted_x_days_ago(8) (0.3ms) SELECT COUNT(*) FROM "posts" WHERE ("posts"."created_at" BETWEEN '2015-02-27 05:00:00.000000' AND '2015-02-26 05:00:00.000000') => 0 Note that the Time on the date is 05:00:00.000000 for both the start