Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Comparing Dates
Parv G.
8/29/2006 10:54:00 PM
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-...
.
2 Answers
Elliot Temple
8/29/2006 11:03:00 PM
0
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
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...
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
http://www.cur...
khaines
8/29/2006 11:04:00 PM
0
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Comparing Dates
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password