Parv_G
(Parv G)
1
Hi,
This might be simple question for some you so.
I'm trying to compare today's dates with another date, which is in the
format of mm/dd/yy. Can somebody help?
I tried the following, but it doesn't work:
require 'date'
if(Date.today <=> "09/29/06") or (Date.today <=> "092906")
.....
else
....
end
Thanks.
···
--
Posted via http://www.ruby-forum.com/.
Your code compares a date and a string. Try comparing two dates. If you don't know how to make a new date, try google or
http://www.rubycentral.com/book/
BTW <=> is probably not what you want to compare with. It always returns a number, and numbers are true, so your if statement doesn't make much sense.
irb(main):010:0> 1 <=> 2
=> -1
irb(main):011:0> 1 <=> 0
=> 1
irb(main):012:0> 1 <=> 1
=> 0
irb(main):013:0>
-- Elliot Temple
···
On Aug 29, 2006, at 3:53 PM, Parv G. wrote:
Hi,
This might be simple question for some you so.
I'm trying to compare today's dates with another date, which is in the
format of mm/dd/yy. Can somebody help?
I tried the following, but it doesn't work:
require 'date'
if(Date.today <=> "09/29/06") or (Date.today <=> "092906")
.....
else
....
end
require 'date'
Date.today == Date.parse('08/29/2006')
Kirk Haines
···
On Wed, 30 Aug 2006, Parv G. wrote:
Hi,
This might be simple question for some you so.
I'm trying to compare today's dates with another date, which is in the
format of mm/dd/yy. Can somebody help?
I tried the following, but it doesn't work:
require 'date'
if(Date.today <=> "09/29/06") or (Date.today <=> "092906")
.....
else
....
end