[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

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

Greg Hauptmann

6/8/2008 3:35:00 AM

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

9 Answers

Nicolas Pelletier

6/8/2008 3:53:00 AM

0

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

Greg Hauptmann

6/8/2008 4:05:00 AM

0

but that's not the format I get the data in :( 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
>
>

miles.sterrett@gmail.com

6/8/2008 4:43:00 AM

0

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

--
MilesZS

Ray Baxter

6/8/2008 5:13:00 AM

0


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

That would work, but so would this:

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



Ray



Greg Hauptmann

6/8/2008 6:38:00 AM

0

[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 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 :( 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-...
>>
>
> That would work, but so would this:
>
> Date.strptime('28/03/2008', '%d/%m/%Y')
>
>
>
> Ray
>
>
>
>

Shankar Narayanan

6/25/2008 9:45:00 AM

0

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

Mark Thomas

6/25/2008 1:31:00 PM

0

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

Shankar Narayanan

6/25/2008 2:32:00 PM

0

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

Mark Thomas

6/25/2008 7:28:00 PM

0

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.

It might. I'm using 1.8.6