From: brabuhr@... Date: 2011-02-03T09:45:56+09:00 Subject: Re: Converting date format (CSV to yaml) > Anyone know how to convert date format of .csv to . yaml? > > .csv date format: > > 12/1/2011 > > .yaml date format: > > 2011-01-12 Another option could be to parse the String into a Date that is then naturally marshaled into the right format. That could help make the intent of the code more clear than splitting and re-arranging by hand, but note that Date.parse changed from Ruby 1.8 to Ruby 1.9. Ruby 1.8 >> require 'date' => true >> require 'yaml' => true >> d = Date.parse('12/1/2011') => # >> puts d.to_yaml --- 2011-12-01 => nil Ruby 1.9 >> require 'date' => true >> require 'yaml' => true >> d = Date.parse('12/1/2011') => # >> puts d.to_yaml --- 2011-01-12 => nil In practice, I sometimes just split it by hand, but I usually try to use strptime: Ruby 1.8 and 1.9: >> d = Date.strptime('12/1/2011', '%d/%m/%Y') => # >> puts d.to_yaml --- 2011-01-12 => nil