ROR + Ruby Date Format For 2 days before from Today Date
In ruby,
@today_date = Time.now.utc.strftime("%Y-%m-%d")
If today date is :: 2011-07-20
But Now I want date before 2 days开发者_StackOverflow :: 2011-07-17
by using Ruby Code. Please suggest something.
Thanks
# 1:
(Time.now - 2.days).utc.strftime....
# 2:
2.days.ago.utc.strftime...
First of all 2011-07-17 is not 2 days before 2011-07-20 but 3..Anyway in Rails:
2.days.ago.strftime("%Y-%m-%d")
In Ruby:
(Time.now-2*24*60*60).strftime("%Y-%m-%d")
Hope I helped..
精彩评论