How to convert a "time difference" into "x days, y hours..."

Hi there,

how can I convert something like…

future_datetime - past_datetime (which results in a float)

into something like…

“21 days, 2 hours, 53 minutes, 1 seconds” ?

Does RoR have any nifty helper for this ?

Thanks a lot for any hint!
Tom

On Apr 11, 4:48 pm, Tom Ha [email protected] wrote:

Hi there,

how can I convert something like…

future_datetime - past_datetime (which results in a float)

into something like…

“21 days, 2 hours, 53 minutes, 1 seconds” ?

Have a look at distance_of_time_in_words
http://api.rubyonrails.org/classes/ActionView/Helpers/DateHelper.html#M001695

Fred

Does RoR have any nifty helper for this ?
Not that I know of, but there’s examples out there…

http://www.google.com/search?q=rails+seconds+to+hours+minutes

This one seems to have the days bit…

http://stufftohelpyouout.blogspot.com/2010/02/seconds-to-days-minutes-hours-seconds.html

Great! Thanks a lot, guys!

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