Date.parse("28/03/2008") gives error???

G

Greg Hauptmann

Hi,

Date.parse("28/03/2008") gives me an error?

I get:

ArgumentError: invalid date.

Any ideas how to fix this?

Versions:
Ruby 1.8.6
Rails 2.0.2
 
G

Greg Hauptmann

but that's not the format I get the data in :( I'm in Australia.

Any ideas?
 
G

Greg Hauptmann

[Note: parts of this message were removed to make it a legal post.]

excellent thanks,
You'd think Ruby would provide some internationalisation type way of solving
this? (e.g. specifying your location/country or something). Guess not?



On Jun 7, 2008, at 9:43 PM, (e-mail address removed) wrote:


Perhaps this link I found can be of use:

http://source.mihelac.org/2006/9/13/parsing-european-date-format-in-ruby-rails

That would work, but so would this:

Date.strptime('28/03/2008', '%d/%m/%Y')



Ray
[/QUOTE]
 
S

Shankar Narayanan

Greg said:
excellent thanks,
You'd think Ruby would provide some internationalisation type way of
solving
this? (e.g. specifying your location/country or something). Guess not?

Hello,

Unfortunately for me, the solution by Ray doesn't seem to work too. For
instance I'm doing this..

dateStr = params[:startdate].to_s
logger.info "date - " + dateStr
startdate =Date.strptime(dateStr, '%m/%d/%Y').to_s

and though I get the string quite correctly as

date - 05/16/2008

I end up getting the ArgumentError - invalid date. Please let me know if
I am doing anything incorrect here.

Regards,
Shankar.
 
M

Mark Thomas

Unfortunately for me, the solution by Ray doesn't seem to work too. For
instance I'm doing this..

dateStr = params[:startdate].to_s
logger.info "date - " + dateStr
startdate =Date.strptime(dateStr, '%m/%d/%Y').to_s

and though I get the string quite correctly as

date - 05/16/2008

I end up getting the ArgumentError - invalid date. Please let me know if
I am doing anything incorrect here.

Doesn't look like it.
Date.strptime("05/16/2008", '%m/%d/%Y').to_s
works for me.
 
S

Shankar Narayanan

Mark said:
Doesn't look like it.
Date.strptime("05/16/2008", '%m/%d/%Y').to_s
works for me.

Does it have anything to do with the version of Ruby/Rails ? I'm using
Rails 1.1.6 and Ruby 1.8.4. Another wierd thing about this is
dateStr.to_time works while dateStr.to_date again gives me the same
exception.
 
M

Mark Thomas

Does it have anything to do with the version of Ruby/Rails ? I'm using
Rails 1.1.6 and Ruby 1.8.4.  Another wierd thing about this is
dateStr.to_time works while dateStr.to_date again gives me the same
exception.

It might. I'm using 1.8.6
 

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

Members online

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,665
Latest member
salkete

Latest Threads

Top