Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > how to get the time difference from 2 DateTime objects

Reply
Thread Tools

how to get the time difference from 2 DateTime objects

 
 
Schüle Daniel
Guest
Posts: n/a
 
      11-21-2006
Hi,

how can I get the time difference in say seconds
between 2 DateTime objects? their difference returns
a rational number which semantic is unclear to me.
(I would expect to get some kind of TimeDelta object
with seconds as its method)

irb(main):107:0* i=DateTime.now;sleep 10;j=DateTime.now;
irb(main):108:0* j-i
=> Rational(10000217, 86400000000)

Thanks in advance
 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      11-21-2006
On 21.11.2006 05:14, Schüle Daniel wrote:
> Hi,
>
> how can I get the time difference in say seconds
> between 2 DateTime objects? their difference returns
> a rational number which semantic is unclear to me.
> (I would expect to get some kind of TimeDelta object
> with seconds as its method)
>
> irb(main):107:0* i=DateTime.now;sleep 10;j=DateTime.now;
> irb(main):108:0* j-i
> => Rational(10000217, 86400000000)
>
> Thanks in advance


>> d1 = DateTime.now; sleep 10; d2 = DateTime.now

=> #<DateTime: 70676958680866127/28800000000,1/12,2299161>
>> diff = d2 - d1

=> Rational(1, 8640)
>> diff.to_f

=> 0.000115740740740741
>> diff.to_f * 24 * 60 * 60

=> 10.0

robert
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
[2.4.4] creating a datetime.datetime from an XML xs:dateTime Martin Python 0 12-27-2008 08:08 PM
mx.DateTime to datetime.datetime mp Python 1 07-28-2006 10:57 PM
datetime: .datetime-.datetime = .timedelta, .time-.time=TypeError ? Christos TZOTZIOY Georgiou Python 3 09-13-2003 10:44 AM
RE: datetime: .datetime-.datetime = .timedelta, .time-.time=TypeError ? Tim Peters Python 0 09-09-2003 12:57 AM



Advertisments