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
Here is a simple one liner:
DateTime.parse date rescue nil
I probably wouldn't recommend doing exactly this in every situation in real life as you force the caller to check for nil, eg. particularly when formatting. If you return a default date|error it may be friendlier.