轨道/ SQL查询帮助:查找所有created_at在每天每过去7天? [英] Rails/SQl query help: Find all by created_at in past 7 days per each day?
本文介绍了轨道/ SQL查询帮助:查找所有created_at在每天每过去7天?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法获得SQL和Rails试图找到过去7天所创建的每一天分类,正确发挥。
I'm unable to get SQL and Rails to play properly when trying to find Categories that are created each day, the past 7 days.
所以基本上我要找到每一个类别排序,他们在过去7天被创造的那一天。
So basically I want to find each Category sorted by the day they were created for the past 7 days.
我发现这对计算器,但没有找到,我就创建了一个类别:
I found this on stackoverflow, but it isn't finding a Category that I just created:
Category.all(:conditions => ["created_at > ? AND created_at < ?", t.at_beginning_of_day, t.tomorrow.at_beginning_of_day])
任何帮助吗?
Any help?
推荐答案
原来这是UTC时间差。
Turns out it was UTC time difference.
range = "created_at #{(5.days.ago.utc...Time.now.utc).to_s(:db)}"
Category.all(:conditions => range)
这是没有的伎俩。 谁能告诉我,如果有更好的方法来做到这一点?
That did the trick. Can anyone tell me if there is a better way to do it?
这篇关于轨道/ SQL查询帮助:查找所有created_at在每天每过去7天?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文