开发者

Ruby on Rails: the best way to compare two dates?

I have a date variable, stored as a String in the 'YYYY-mm-dd' format. What is the best way to check, if that date开发者_如何学Go has not already passed?


Date.parse('2010-11-01') < Date.today

will return true if '2010-11-01' has already passed


You can also use past?

Date.parse("2012-11-01").past?


If you want to compare some attributes of dates, you can do this too:

Date.parse('2010-11-01').month < Date.today.month
Date.parse('2010-11-01').year < Date.today.year
Date.parse('2010-11-01').day < Date.today.day
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜