funny date parsing

J

Junkone

i enter 2008 and it becomes 0008

irb(main):009:0> Date.parse("04-Feb-08").strftime('%Y-%m-%d')
=> "0008-02-04"
 
D

David A. Black

Hi --

i enter 2008 and it becomes 0008

irb(main):009:0> Date.parse("04-Feb-08").strftime('%Y-%m-%d')
=> "0008-02-04"

You've entered 08, not 2008.


David

--
Rails training from David A. Black and Ruby Power and Light:
ADVANCING WITH RAILS April 14-17 New York City
INTRO TO RAILS June 9-12 Berlin
ADVANCING WITH RAILS June 16-19 Berlin
See http://www.rubypal.com for details and updates!
 
J

Junkone

Hi --




You've entered 08, not 2008.

David

--
Rails training from David A. Black and Ruby Power and Light:
   ADVANCING WITH RAILS   April 14-17          New York City
   INTRO TO RAILS         June 9-12            Berlin
   ADVANCING WITH RAILS   June 16-19           Berlin
Seehttp://www.rubypal.comfor details and updates!

oh ok. but all my date formats are like that and i am trying to import
it. is n't there a y2k rule somewhere on detecting 08 as 2008. i could
be wrong. can someone give me a workaround there.

seede
 
C

Chris Shea

oh ok. but all my date formats are like that and i am trying to import
it. is n't there a y2k rule somewhere on detecting 08 as 2008. i could
be wrong. can someone give me a workaround there.

seede

Date.parse has an optional second argument for handling near-2000 two-
digit years.

001:0> Date.parse('04-Feb-08', true).strftime('%Y-%m-%d')
"2008-02-04"

See documentation here: http://www.ruby-doc.org/core/classes/Date.html#M000656

HTH,
Chris
 

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,289
Messages
2,571,448
Members
48,126
Latest member
ToneyChun2

Latest Threads

Top