3

I tried parsing using

Date.parse("28-May-10").to_s

Returns 0010-5-28 (which is 2000 years off!)

How can I get ruby to interpret the two digit year properly.

There are plenty of string to date conversion tricks out there on google but most handle digit months as opposed to "May".

knut
  • 27,320
  • 6
  • 84
  • 112
Tarang
  • 75,157
  • 39
  • 215
  • 276

1 Answers1

10

I prefer Date.strptime for this task:

require 'date'
puts Date.strptime("28-May-10", "%d-%b-%y") #2010-05-28
knut
  • 27,320
  • 6
  • 84
  • 112