Forum: Ruby on Rails Which is the best way for comparing dates?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
71e53b54803415f87ef1b898baf8f3ca?d=identicon&s=25 John Smith (terry_wolf)
on 2009-02-13 19:42
Is it correct to do this?
 if @date_a > @date_b
puts 'hi'
end
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-02-13 19:54
(Received via mailing list)
On 13 Feb 2009, at 18:42, John Smith wrote:

>
> Is it correct to do this?
> if @date_a > @date_b
> puts 'hi'
> end

assuming those are both instances of Date, (or Time etc.) then yes.
Ruby won't let you compare an instance of Date with a Time instance,
and equally funny things will happen if either (or both) of those are
string representations of the dates.

Fred
71e53b54803415f87ef1b898baf8f3ca?d=identicon&s=25 John Smith (terry_wolf)
on 2009-02-13 20:42
Thanks Fred. Those ones are the updated_at rows of two different tables.
247cd3d37084a3d6794076207bd9fbd7?d=identicon&s=25 Bob Martens (Guest)
on 2009-02-14 08:24
(Received via mailing list)
I think you'll be good to go with that one.

On Feb 13, 1:42 pm, John Smith <rails-mailing-l...@andreas-s.net>
This topic is locked and can not be replied to.