Forum: Ruby on Rails Difference in minutes betwen two Datetime

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Günther L. (Guest)
on 2008-12-05 13:02
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
Daniel B. (Guest)
on 2008-12-05 15:29
(Received via mailing list)
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.
Cesar D. (Guest)
on 2008-12-05 16:35
(Received via mailing list)
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
ABHILASH M. (Guest)
on 2011-03-09 18:10
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
Colin L. (Guest)
on 2011-03-09 18:29
(Received via mailing list)
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
Jim ruther N. (Guest)
on 2011-03-10 01:57
(Received via mailing list)
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 :D


> --
> 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.
>
>


--
This topic is locked and can not be replied to.