How to get time difference in days,hours,mins
I am trying to do
datetime_A - datetime_B
datetime_A
= Sat, 04 Jan 2014 07:00:13 +0000
datetime_B
= Fri, 03 Jan 2014 01:09:46 +0000
it returns me something like(35809/28800)
,bdw what does it means?
I need like 1day,5h,23min
How can do it?
I like to use the gem time_diff
https://github.com/abhidsm/time_diff
Here is a example how it works
Time.diff(Time.parse('2011-03-06'), Time.parse('2011-03-07'))
# => {:year => 0, :month => 0, :week => 0, :day => 1, :hour => 0, :minute => 0, :second => 0, :diff => '1 day and 00:00:00'}
An alternative could be to use the ActionView
helper distance_of_time_in_words
(see the documentation). If normally does not give the exact minor units, but something like "around 5 days".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With