Eugene
Eugene

Reputation: 689

How to determine the difference in dates in ruby

I have some problem with comparing dates. I need to compare more than DateTime.now or record.updated_at for 7 days. I try do something like that: DateTime.now - record.updated_at but have result as that 143587.77856945992 or (14358777856939/8640000000000). I dont understand what is that. Maybee need convert to Time format or something else? Thanks

Upvotes: 0

Views: 52

Answers (2)

Sucrenoir
Sucrenoir

Reputation: 3034

Use:

((DateTime.now - record.updated_at) * 24 * 60 * 60).to_i

to get the number of seconds

(DateTime.now - record.updated_at).to_i

to get the number of days (obviously...)

Upvotes: 1

Aayush Khandelwal
Aayush Khandelwal

Reputation: 1071

If you want in words then you can use distance_of_time_in_words

Upvotes: 1

Related Questions