Difference in minutes betwen two Datetime

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

On Dec 5, 10:02 pm, Günther Lackner [email protected]
wrote:

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?

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.


Daniel B.

why you don’t use distance_of_time_in_words()?

you can rewrite maybe this method in a helper and customize.


http://www.sindominio.net/ayuda/preguntas-inteligentes.html
http://cronopios.net/Traducciones/trolls.es.html
Gnu/Linux count user #416024

Pagina personal : http://www.cesardiaz.com.ar
Mi blog : http://cesarediaz.blogspot.com
Skype: cesarstafe

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 time_diff | RubyGems.org | your community gem host

It returns the difference in a hash

On 9 March 2011 16:10, ABHILASH M.A [email protected] wrote:

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

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

On Thu, Mar 10, 2011 at 12:10 AM, ABHILASH M.A [email protected]
wrote:

diff is in seconds. so just divide it by 60 :smiley:


You received this message because you are subscribed to the Google G.
“Ruby on Rails: Talk” group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.