Parse Date string in Ruby
You could use the Date.strptime method provided in Ruby’s Standard Library: require ‘date’ string = “20120723” date = Date.strptime(string,”%Y%m%d”) Alternately, as suggested in the comments, you could use Date.parse, because the heuristics work correctly in this case: require ‘date’ string = “20120723” date = Date.parse(string) Both will raise an ArgumentError if the date is not … Read more