Comparing Dates

P

Parv G.

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.
 
E

Elliot Temple

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.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
http://www.curi.us/blog/
 
K

khaines

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Sorting Array Of Dates 8
Comparing dates from database 5
Taskcproblem calendar 4
Comparing dates using JSTL 0
Ruby 1.9.2 Date issues 2
Help with code plsss 0
[ANN] tod - Time of day 0
calculating an array of dates 4

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top