I have a string: \"31-02-2010\" and want to check whether or not it is a valid date. What is the best way to do it?
\"31-02-2010\"
I need a method which which returns
Method:
require 'date' def is_date_valid?(d) Date.valid_date? *"#{Date.strptime(d,"%m/%d/%Y")}".split('-').map(&:to_i) rescue nil end
Usage:
config[:dates].split(",").all? { |x| is_date_valid?(x)}
This returns true or false if config[:dates] = "12/10/2012,05/09/1520"