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

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

Hello,

···

On Sun, Jun 8, 2008 at 12:35 PM, Greg Hauptmann <greg.hauptmann.ruby@gmail.com> wrote:

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

Try:

Date.parse("03/28/2008")

--
Nico

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

Any ideas?

···

On 6/8/08, Nicolas Pelletier <nicolas.pelletier3@gmail.com> wrote:

Hello,

On Sun, Jun 8, 2008 at 12:35 PM, Greg Hauptmann > <greg.hauptmann.ruby@gmail.com> wrote:

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

Try:

Date.parse("03/28/2008")

--
Nico

Perhaps this link I found can be of use:
http://source.mihelac.org/2006/9/13/parsing-european-date-format-in-ruby-rails

···

On Jun 8, 12:04 am, Greg Hauptmann <greg.hauptmann.r...@gmail.com> wrote:

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

Any ideas?

On 6/8/08, Nicolas Pelletier <nicolas.pelleti...@gmail.com> wrote:

> Hello,

> On Sun, Jun 8, 2008 at 12:35 PM, Greg Hauptmann > > <greg.hauptmann.r...@gmail.com> wrote:

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

> Try:

> Date.parse("03/28/2008")

> --
> Nico

--
MilesZS

That would work, but so would this:

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

Ray

···

On Jun 7, 2008, at 9:43 PM, miles.sterrett@gmail.com wrote:

On Jun 8, 12:04 am, Greg Hauptmann <greg.hauptmann.r...@gmail.com> > wrote:

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

Any ideas?

On 6/8/08, Nicolas Pelletier <nicolas.pelleti...@gmail.com> wrote:

Hello,

On Sun, Jun 8, 2008 at 12:35 PM, Greg Hauptmann >>> <greg.hauptmann.r...@gmail.com> wrote:

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

Try:

Date.parse("03/28/2008")

--
Nico

Perhaps this link I found can be of use:
http://source.mihelac.org/2006/9/13/parsing-european-date-format-in-ruby-rails

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 Sun, Jun 8, 2008 at 3:13 PM, Ray Baxter <ray.baxter@gmail.com> wrote:

On Jun 7, 2008, at 9:43 PM, miles.sterrett@gmail.com wrote:

On Jun 8, 12:04 am, Greg Hauptmann <greg.hauptmann.r...@gmail.com> >> wrote:

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

Any ideas?

On 6/8/08, Nicolas Pelletier <nicolas.pelleti...@gmail.com> wrote:

Hello,

On Sun, Jun 8, 2008 at 12:35 PM, Greg Hauptmann >>>> <greg.hauptmann.r...@gmail.com> wrote:

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

Try:

Date.parse("03/28/2008")

--

Nico

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

Greg Hauptmann wrote:

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.

···

--
Posted via http://www.ruby-forum.com/\.

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.

Mark Thomas wrote:

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.

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.

···

--
Posted via http://www.ruby-forum.com/\.

It might. I'm using 1.8.6

···

On Jun 25, 10:31 am, Shankar Narayanan <subscribe...@gmail.com> wrote:

Mark Thomas wrote:

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

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.