ruby on rails - Calculating difference in time between two Time objects -


let's create 2 time objects user model:

created = u.created_at updated = u.updated_at 

how calculate difference in terms of hours between 2 time objects?

hours = created - updated 

i'd wrap in method , extend time class. find hard believe i'd need extend it, can't seem find native method handles calculating elapsed time using different time units.

this should work:

hours = ((created - updated) / 1.hour).round 

related question: rails time difference in hours


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -