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.
Mecharek M. (Guest)
on 2007-06-15 13: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
Daniel -. (Guest)
on 2007-06-15 13:38
(Received via mailing list)
On 6/15/07, Mecharek M. <removed_email_address@domain.invalid>
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.