hi, Is there an easy way of calculating the difference in months between two dates in a controller. thanks -- Posted via http://www.ruby-forum.com/.
ben
2006-Jul-07 12:59 UTC
[Rails] Re: calculate number of months difference between two dates
ben wrote:> hi, > > Is there an easy way of calculating the difference in months between two > dates in a controller. > > thankswell this is how I have done it, just out of interest, im going to need to build a few more date functions like this, how would I go about creating a plugin to include this? pLoopDate = Date.new(2005,10,1) pLoopDateMax = Date.new(2006, 10, 1) while pLoopDate <= pLoopDateMax pNumberOfMonths = pNumberOfMonths + 1 if pLoopDate.month == 12 pLoopDate = Date.new((pLoopDate.year+1),1,1) else pLoopDate = Date.new(pLoopDate.year,(pLoopDate.month+1),1) end end -- Posted via http://www.ruby-forum.com/.
Carl-Johan Kihlbom
2006-Jul-07 13:19 UTC
[Rails] calculate number of months difference between two dates
On 7/7/06, ben <ben@streamd.com> wrote:> hi, > > Is there an easy way of calculating the difference in months between two > dates in a controller.You could do (date2.year*12+date2.month) - (date1.year*12+date1.month). / CJ
Adi Glasman
2006-Aug-03 07:54 UTC
[Rails] calculate number of months difference between two dates
Use the date helper for this date diff issues, ActionView::Helpers::DateHelper Check out distance_of_time_in_words -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Carl-Johan Kihlbom Sent: Friday, July 07, 2006 4:19 PM To: rails@lists.rubyonrails.org Subject: Re: [Rails] calculate number of months difference between two dates On 7/7/06, ben <ben@streamd.com> wrote:> hi, > > Is there an easy way of calculating the difference in months betweentwo> dates in a controller.You could do (date2.year*12+date2.month) - (date1.year*12+date1.month). / CJ _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails