To get time differnece in hours between two time values

S

Sijo Kg

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
 
P

Pierre Pat

Sijo said:
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.
 
F

Florian Aßmann

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

Am 27.11.2008 um 06:48 schrieb Pierre Pat:
 
R

Robert Dober

(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
--=20
Ne baisse jamais la t=EAte, tu ne verrais plus les =E9toiles.

Robert Dober ;)
 
F

Florian Aßmann

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 =20=

these nn chars into this e-mail.

Cheers
Florian

Am 27.11.2008 um 12:03 schrieb Robert Dober:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,135
Latest member
VeronaShap
Top