Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 - Time Comparison?

I'm working to do the following in my Rails App:

if record.updated_at > 15.minutes.ago do some stuff end

Meaning... If the record.updated_at was over 15 minutes ago, do some stuff...

This doesn't seem to be working. Ideas?

like image 987
TheExit Avatar asked Oct 29 '10 02:10

TheExit


2 Answers

You want:

if record.updated_at < 15.minutes.ago

That's "less-than" as in "before".

like image 179
Steve Ross Avatar answered Oct 20 '22 22:10

Steve Ross


Greater than or less than should work, depending on which you mean. 15.minutes.ago returns a time object that should compare properly with record.updated_at. When you say it "doesn't seem to be working", could you be more specific? Also, if you could show a few more lines of code it may help. For example, if you're doing this all on one line then you're missing some syntax.

like image 28
jwarchol Avatar answered Oct 20 '22 21:10

jwarchol