开发者

ROR + Ruby Date Format For 2 days before from Today Date

开发者 https://www.devze.com 2023-03-21 20:25 出处:网络
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 som

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..

0

精彩评论

暂无评论...
验证码 换一张
取 消