To get time differnece in hours between two time values

Hi
    I have two values like incidents.first.created_on and Time.now
bothe are of class Time Now I would like to get differnet between these
two in hours I gtried like

(Time.now-incidents.first.created_on).hours
     But getting wrong result..Could you please tell how I can do this?

Thanks in advance
Sijo

···

--
Posted via http://www.ruby-forum.com/.

Sijo Kg wrote:

Hi
    I have two values like incidents.first.created_on and Time.now
bothe are of class Time Now I would like to get differnet between these
two in hours I gtried like

(Time.now-incidents.first.created_on).hours
     But getting wrong result..Could you please tell how I can do this?

Thanks in advance
Sijo

Time.now-incidents.first.created_on will return you the number of
seconds in Numeric, that's why you can't call the method 'hours' on it.
I haven't seen a method which would convert seconds in hours for you, if
there really isn't one, you'll have to make the convertion to hours
yourself...

Cheers.

···

--
Posted via http://www.ruby-forum.com/\.

(Time.now - incidents.first.created_on) / 1.hour

···

Am 27.11.2008 um 06:48 schrieb Pierre Pat:

Sijo Kg wrote:

Hi
   I have two values like incidents.first.created_on and Time.now
bothe are of class Time Now I would like to get differnet between these
two in hours I gtried like

(Time.now-incidents.first.created_on).hours
    But getting wrong result..Could you please tell how I can do this?

Thanks in advance
Sijo

Time.now-incidents.first.created_on will return you the number of
seconds in Numeric, that's why you can't call the method 'hours' on it.
I haven't seen a method which would convert seconds in hours for you, if
there really isn't one, you'll have to make the convertion to hours
yourself...

Cheers.
--
Posted via http://www.ruby-forum.com/\.

Hi
   Thanks for the reply
Sijo

···

--
Posted via http://www.ruby-forum.com/.

I do not think that 1 responds to that message.
but using 3600 instead should do the trick.
HTH
Robert

···

On Thu, Nov 27, 2008 at 7:57 AM, Florian Aßmann <florian.assmann@email.de> wrote:

(Time.now - incidents.first.created_on) / 1.hour

--
Ne baisse jamais la tête, tu ne verrais plus les étoiles.

Robert Dober :wink:

(Time.now - incidents.first.created_on) / 1.hour

I do not think that 1 responds to that message.

Neither do I...
However, if you are using Rails and ok with requiring active_support, that enables 1.hour for you.

but using 3600 instead should do the trick.

In this case I'd vote for this option.

Cheers,
Peter

···

On 2008.11.27., at 12:03, Robert Dober wrote:

On Thu, Nov 27, 2008 at 7:57 AM, Florian Aßmann > <florian.assmann@email.de> wrote:

___
http://www.rubyrailways.com
http://scrubyt.org

Hi Robert,

the original code:

(Time.now-incidents.first.created_on).hours

almost implies that it uses a framework like Rails so I naively blown these nn chars into this e-mail.

Cheers
Florian

···

Am 27.11.2008 um 12:03 schrieb Robert Dober:

On Thu, Nov 27, 2008 at 7:57 AM, Florian Aßmann > <florian.assmann@email.de> wrote:

(Time.now - incidents.first.created_on) / 1.hour

I do not think that 1 responds to that message.
but using 3600 instead should do the trick.
HTH
Robert
--
Ne baisse jamais la tête, tu ne verrais plus les étoiles.

Robert Dober :wink: