Reputation: 13558
Let's say I want to find out the difference in seconds between two times. One of the times is the created_at
attribute of the element, and the other time is a random fixed time in the past. How would I find the difference between the two, and transform it into seconds?
Upvotes: 0
Views: 623
Reputation: 5046
It should be as simple as:
time = Time.now
offset = time - record.created_at
offset
will now be a Float which is the difference in seconds between the two compared Time objects.
Upvotes: 2
Reputation: 5455
Lucky for you the -
operator in ruby returns you an float which is the difference in seconds.
difference_in_seconds = x.created_at - random_time_in_past
Upvotes: 4