Difference in minutes betwen two Datetime


#1

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


#2

On Dec 5, 10:02 pm, Günther Lackner removed_email_address@domain.invalid
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.


#3

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


#4

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

It returns the difference in a hash


#5

On 9 March 2011 16:10, ABHILASH M.A removed_email_address@domain.invalid 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


#6

On Thu, Mar 10, 2011 at 12:10 AM, ABHILASH M.A removed_email_address@domain.invalid
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 removed_email_address@domain.invalid.
To unsubscribe from this group, send email to
removed_email_address@domain.invalid.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.