Comparing dates in rails

Yes, you can use comparison operators to compare dates e.g.:

irb(main):018:0> yesterday = Date.new(2009,6,13)
=> #<Date: 4909991/2,0,2299161>
irb(main):019:0> Date.today > yesterday
=> true

But are you trying to compare a date to a datetime?

If that’s the case, you’ll want to convert the datetime to a date then do the comparison.

I hope this helps.

Leave a Comment