Hi!
I need to calculate the difference between two Datetime and convert it into minutes.
diff = Time.now() - my_date
How can I convert diff now into minutes?
Best regards lacky
Hi!
I need to calculate the difference between two Datetime and convert it into minutes.
diff = Time.now() - my_date
How can I convert diff now into minutes?
Best regards lacky
What class is my_date ? (my_date.class) Is it DateTime, or is TIme or ActiveSupport::TimeWithZone ? In general, the difference seems to be in seconds when you subtract two objects of the same class so you'd divide by 60 to get minutes. I think you can also subtract between Time and TimeWithZone but you may run into trouble with other combinations.
why you don't use distance_of_time_in_words()?
you can rewrite maybe this method in a helper and customize.
Günther Lackner wrote in post #756895:
Hi!
I need to calculate the difference between two Datetime and convert it into minutes.
diff = Time.now() - my_date
How can I convert diff now into minutes?
Best regards lacky
Try https://rubygems.org/gems/time_diff/stats
It returns the difference in a hash
ruby-1.8.7-p302 > t1 = Time.now => Wed Mar 09 16:24:09 +0000 2011 ruby-1.8.7-p302 > t2 = Time.now => Wed Mar 09 16:24:22 +0000 2011 ruby-1.8.7-p302 > t2 - t1 => 12.607967
The difference is in seconds. I think your my_date variable is not a Time or DateTime object.
Colin
Günther Lackner wrote in post #756895:
Hi!
I need to calculate the difference between two Datetime and convert it
into minutes.
diff = Time.now() - my_date
How can I convert diff now into minutes?
diff is in seconds. so just divide it by 60