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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 5, 10:02 pm, Günther Lackner <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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 Bush --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 > lackyTry https://rubygems.org/gems/time_diff/stats It returns the difference in a hash -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 9 March 2011 16:10, ABHILASH M.A <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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_dateruby-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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Thu, Mar 10, 2011 at 12:10 AM, ABHILASH M.A <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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 > > > > How can I convert diff now into minutes? > > >diff is in seconds. so just divide it by 60 :D> > Best regards > > lacky > > Try https://rubygems.org/gems/time_diff/stats > > It returns the difference in a hash > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.com -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.