Hi- So, say I have 2 DateTimes and I want to display the difference in mm:ss, how would I do this without manipulating each individual component, while still displaying the true number of minutes and seconds (i/e/ not just t.min, or t.sec)? Thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> Hi- > > So, say I have 2 DateTimes and I want to display the difference in > mm:ss, how would I do this without manipulating each individual > component, while still displaying the true number of minutes and > seconds (i/e/ not just t.min, or t.sec)?a>> a = 15.minutes.ago => Tue Mar 04 12:35:08 -0800 2008>> b = Time.now=> Tue Mar 04 12:50:10 -0800 2008>> b - a=> 902.319528>> "%02d" % ((b - a) / 60).to_i + '':'' + "%02d" % ((b - a) % 60).to_i=> "15:02" --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks! On Mar 4, 8:52 pm, Philip Hallstrom <phi...-LSG90OXdqQE@public.gmane.org> wrote:> > Hi- > > > So, say I have 2 DateTimes and I want to display the difference in > > mm:ss, how would I do this without manipulating each individual > > component, while still displaying the true number of minutes and > > seconds (i/e/ not just t.min, or t.sec)? > > a>> a = 15.minutes.ago > => Tue Mar 04 12:35:08 -0800 2008>> b = Time.now > > => Tue Mar 04 12:50:10 -0800 2008>> b - a > => 902.319528 > >> "%02d" % ((b - a) / 60).to_i + '':'' + "%02d" % ((b - a) % 60).to_i > > => "15:02"--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---