PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > Date.parse("28/03/2008") gives error???
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Date.parse("28/03/2008") gives error???

Réponse
 
LinkBack Outils de la discussion
Vieux 08/06/2008, 04h35   #1
Greg Hauptmann
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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

  Réponse avec citation
Vieux 08/06/2008, 04h52   #2
Nicolas Pelletier
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Date.parse("28/03/2008") gives error???

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

  Réponse avec citation
Vieux 08/06/2008, 05h04   #3
Greg Hauptmann
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Date.parse("28/03/2008") gives error???

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


  Réponse avec citation
Vieux 08/06/2008, 05h42   #4
miles.sterrett@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Date.parse("28/03/2008") gives error???

On Jun 8, 12:04am, 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/...-in-ruby-rails

--
MilesZS
  Réponse avec citation
Vieux 08/06/2008, 06h13   #5
Ray Baxter
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Date.parse("28/03/2008") gives error???


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/...-in-ruby-rails


That would work, but so would this:

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



Ray



  Réponse avec citation
Vieux 08/06/2008, 07h37   #6
Greg Hauptmann
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Date.parse("28/03/2008") gives error???

[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/...-in-ruby-rails
>>

>
> That would work, but so would this:
>
> Date.strptime('28/03/2008', '%d/%m/%Y')
>
>
>
> Ray
>
>
>
>


  Réponse avec citation
Vieux 25/06/2008, 10h45   #7
Shankar Narayanan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Date.parse("28/03/2008") gives error???

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

  Réponse avec citation
Vieux 25/06/2008, 14h31   #8
Mark Thomas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Date.parse("28/03/2008") gives error???

> 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.
  Réponse avec citation
Vieux 25/06/2008, 15h31   #9
Shankar Narayanan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Date.parse("28/03/2008") gives error???

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

  Réponse avec citation
Vieux 25/06/2008, 20h27   #10
Mark Thomas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Date.parse("28/03/2008") gives error???

On Jun 25, 10:31am, 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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 23h04.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,17256 seconds with 18 queries