Find total months passed between two ActiveSupport::TimeWithZone objects

unit.created_at.class
=> ActiveSupport::TimeWithZone

Time.zone.now.class
=> ActiveSupport::TimeWithZone

Time.zone.now - unit.created_at
=> 47709736.32316899

I think that’s the number of seconds that have passed between when the
unit
was created and the current time. Is this correct? If so, is there any
easier way to find the total months that passed between two time objects
like this?

On Thursday, 26 September 2013 16:35:30 UTC-5, John M. wrote:

I think that’s the number of seconds that have passed between when the
unit was created and the current time. Is this correct? If so, is there any
easier way to find the total months that passed between two time objects
like this?

(Time.zone.now - unit.created_at) / 1.month, perhaps?

–Matt J.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs