Date.strptime with format '%m/%d/%Y'
require 'date'
four_digit_year_date = '%m/%d/%Y'
puts Date.strptime('2/9/2007', four_digit_year_date).to_s # => "2007-02-09"
puts Date.strptime('02/09/1968', four_digit_year_date).to_s # => "1968-02-09"
puts Date.strptime('2/9/69', four_digit_year_date).to_s # => "0069-02-09"
Related examples in the same category