Forum: Ruby on Rails comparind 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.
36b16df88c6edd79f2e28392741d9258?d=identicon&s=25 Mecharek Massinissa (massi)
on 2007-06-15 11:14
hello,

i have to dates :

@date_1 = date.new()

@date_2 = date.new()

i want to compare theses two dates

 i have tried

  @date_1 > @ date_2 but every time it returns me FALSE


is there a solution .?????

thanks
9d1f5d2d9de70bd9a934f557dc95a406?d=identicon&s=25 Daniel ----- (liquid)
on 2007-06-15 11:38
(Received via mailing list)
On 6/15/07, Mecharek Massinissa <rails-mailing-list@andreas-s.net>
wrote:
> i want to compare theses two dates
>
> i have tried
>
>   @date_1 > @ date_2 but every time it returns me FALSE
>
>
> is there a solution .?????
>
> thanks


This is returning false because the same date is returned by a call to
Date.new which defaults to 0. ( Mon, 01 Jan -4712 )

Instead you could use
Date.today > ( Date.today - 1 )  # => true
Date.civil( 2007, 12, 31 ) > Date.civil( 2007, 12, 30 ) # => true

Hope that helps.

Cheers
This topic is locked and can not be replied to.