Reputation: 2982
Rails 2.3.5 / Ruby 1.8.6
Looking for how to do this without the Rails 3 week classes. I need to get the dates (2011-10-16, etc) for: -The Sunday date of the current week -The Sunday date of the previous 4 weeks
Thanks!
Upvotes: 1
Views: 827
Reputation: 2982
I thought beginning_of_week was only in Rails 3 but this actually works fine in Rails 2:
sunday_this_week = (Time.now.beginning_of_week - 1.days).strftime("%Y-%m-%d")
sunday_1_week_ago = (Time.now.beginning_of_week - 8.days).strftime("%Y-%m-%d")
sunday_2_week_ago = (Time.now.beginning_of_week - 15.days).strftime("%Y-%m-%d")
sunday_3_week_ago = (Time.now.beginning_of_week - 22.days).strftime("%Y-%m-%d")
sunday_4_week_ago = (Time.now.beginning_of_week - 29.days).strftime("%Y-%m-%d")
Upvotes: 0
Reputation: 160181
I rely on the chronic library for such things, because I don't have to think too much to use it.
Upvotes: 1